Post Top Ad

Post Top Ad

akses thingspeak dengan node mcu

//#include <ESP8266WiFiMulti.h>
//#include <ESP8266HTTPClient.h>
//ESP8266WiFiMulti WiFiMulti;

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
ESP8266WiFiMulti WiFiMulti;

int lamp = 2;




String serialString = "";
boolean serialComplete = false;
String alamat = "http://api.thingspeak.com/update?api_key=FI27INTP2EUSYC75";
//http://192.168.43.195/restapi/webserviceiotfinish.php/
//?waktu_a=01:55:58&tanggal_a=01/01/01&waktu_b=01:55:58&tanggal_b=01/01/01&pulsa_ukur=0.00&pulsa_kalib=0.00&volume_bahan=0.00&volume_hasil=0.00&rendemen=0.00&operator=taufik%20adi&keterangan=kalib&no_separator=1

void setup()
{
// delay(1000);

  Serial.begin(9600);
  pinMode(lamp, OUTPUT);
   WiFi.mode(WIFI_STA);
   WiFiMulti.addAP("Adminku", "88888888");
 // WiFiMulti.addAP("Andromax-M2Y-0379", "20594431");
// WiFiMulti.addAP("ASUS_X00TD", "1234567890");

}


void loop()
{
 // tunggu koneksi Wifi
    if((WiFiMulti.run() == WL_CONNECTED))
    {
  //  Serial.println("konek");
     digitalWrite(lamp, LOW);
   
 
     if  (Serial.available() > 0)
    {
    char serialChar = Serial.read();
    serialString += serialChar;

    if (serialChar == ' ') {
    serialChar='%20';
    }

   
    if (serialChar == '\n')
      {
      serialComplete = true;
      serialString.trim();
      //Serial.println("OK");
      Serial.println(alamat+serialString);
      }
    }


  if (serialComplete==true) {
 // HTTPClient http1;
  HTTPClient http;
 
  http.begin(alamat+serialString);
  //http.begin("http://api.thingspeak.com/update?api_key=FI27INTP2EUSYC75&field1=0.00&field2=5.00&field3=10.00");
  //http.begin("https://api.thingspeak.com/update?api_key=FI27INTP2EUSYC75&field1=10&field2=10&field3=10");
  Serial.println(alamat+serialString);
  Serial.println("REQUEST");
  int httpCode = http.GET();
  serialString="";
  serialComplete = false;



  if(httpCode > 0)
  {
    if(httpCode == HTTP_CODE_OK)
     {
      String textdariservice = http.getString();
      Serial.println(textdariservice);
     }
   }
   else {
              Serial.println("[HTTP] GET... failed");
          }
           
    http.end();

  }
   
    }
 
}





catatan : jangan make https pake lah http saja