Things used in this project

Hardware components:
Nodemcu
NodeMCU ESP8266 Breakout Board
×1
Software apps and online services:
Messenger
Logo transp
Das Coisas Taurus Platform

Code

NodeMCU codeArduino
/**
 * Leonardo Gonçalves - Das Coisas IoT Solutions
 *
 *
 *
 */

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;
String ID = "ACTUATOR_ID";
int VAR = 0;
String GET, GETCREATE;
String V;
void setup() {

  USE_SERIAL.begin(115200);
  // USE_SERIAL.setDebugOutput(true);
  pinMode(BUILTIN_LED, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
  USE_SERIAL.println();
  USE_SERIAL.println();
  USE_SERIAL.println();
  digitalWrite(BUILTIN_LED, HIGH);
  for (uint8_t t = 4; t > 0; t--) {
    USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
    USE_SERIAL.flush();
    delay(1000);
  }

  WiFiMulti.addAP("SSID", "PASSWORD");

}

void loop() {
  // wait for WiFi connection
  if ((WiFiMulti.run() == WL_CONNECTED)) {
    HTTPClient http;
    URL();
    USE_SERIAL.print("[HTTP] begin...\n");
    // configure traged server and url
    //http.begin("192.168.1.12", 443, "/test.html", true, "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
    http.begin("104.131.189.228", 80, GET); //HTTP
    USE_SERIAL.print("[HTTP] GET...\n");
    // start connection and send HTTP header
    int httpCode = http.GET();
    if (httpCode) {
      // HTTP header has been send and Server response header has been handled
      USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

      // file found at server
      //if(httpCode == 200) {
      String payload = http.getString();
      int posicao = payload.indexOf(ID);
      if (posicao == -1 && httpCode == 200)
      {
        //CREATE();
      }
      String dado = payload.substring(posicao + 5, posicao + 6);
      USE_SERIAL.print("Dado: ");
      USE_SERIAL.println(dado);
      if (dado == "1")
      {
        digitalWrite(BUILTIN_LED, LOW);//ANODO COMUM, ACENDE COM LOW
      }
      if (dado == "0")
      {
        digitalWrite(BUILTIN_LED, HIGH);
      }
      USE_SERIAL.println(payload);
      //}
    } else {
      USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
    }
  }
  delay(1000);
}

void URL(void)
{
  GET = "http://104.131.189.228/ws/webresources/GetDigitais?key=SERIAL"; // Put your Taurus Serial Here!
  String estado = ",0)";
  GETCREATE = "http://104.131.189.228/ws/webresources/Create?key=SERIAL&&load=(";// Put your Taurus Serial Here!
  GETCREATE = GETCREATE + ID + estado;
  /*
  VAR++;
  V = String(VAR);
  USE_SERIAL.println(V);
  GET=GET+V;*/
}
void CREATE(void)
{
  URL();
  HTTPClient http;
  USE_SERIAL.println("Componente não existente, criando ...");
  http.begin("104.131.189.228", 80, GETCREATE); //HTTP
  USE_SERIAL.print("[HTTP] GET...\n");
  // start connection and send HTTP header
  int httpCode = http.GET();
  if (httpCode) {
    // HTTP header has been send and Server response header has been handled
    USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

    // file found at server
    //if(httpCode == 200) {
    String payload = http.getString();
    int posicao = payload.indexOf(ID);
  }
}

Credits

1510947 574075536015733 1458936564 n
Leonardo Ribeiro Gonçalves

Master Degree Student at Federal University of Itajuba - Brazil / Telecommunications Engineer graduated at Inatel - Minas Gerais - Brazil

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

ESP8266 NodeMCU WiFi IoT Garage Door Opener Relay with Cayen
Easy
  • 56
  • 3

In this project, we will use an ESP8266 with Cayenne to control a Garage Door Opener.

Safe City: A Device to Keep You Safe
Easy
  • 630
  • 6

Full instructions

The device will keep you safe. Just have to click a button and your precise location will be shared.

Web-Based Universal Remote for Under $4 (Probably)
Easy
  • 1,600
  • 9

Don't buy a universal remote, make one. It's cheaper, funner, universal-er, kind of, and you get to learn the ESP8266, kind of.

ESP8266 Temperature Monitor
Easy
  • 1,929
  • 11

Full instructions

Get an alert if your fridge's temperature rises above 40 F (very dangerous!).

NodeMCU, Dweet.io & Freeboard.io
Easy
  • 8
  • 1

A simple IoT test to monitor analog values of a potentiometer & a thumbstick using Dweet.io & Freeboard.

How to Communicate with ESP8266 via Arduino UNO
Easy
  • 522
  • 5

Protip

As ESP8266 works on 3.3V and not 5v, it is important to perform this task.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog