Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ESP8266WiFi.h"
- #include <ESP8266HTTPClient.h>
- #include <ArduinoJson.h>
- //SSID of your network
- char ssid[] = "ELITE_GLOBAL"; //SSID of your Wi-Fi router
- char pass[] = "assasin_cok"; //Password of your Wi-Fi router
- void setup()
- {
- Serial.begin(115200);
- Serial.print("Sedang Menghubungkan -> ");
- Serial.print(ssid);
- WiFi.begin(ssid, pass);
- dht.begin();
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
- Serial.println(" ");
- Serial.print("Terhubung , IP address : ");
- Serial.println(WiFi.localIP());
- }
- void loop() {
- Serial.println("========= OUTPUT ============");
- tampil();
- Serial.println("=============================");
- Serial.println(" ");
- delay(3000);
- }
- void tampil()
- {
- HTTPClient http;
- http.begin("http://ferrynurr.000webhostapp.com/kelembaban"); // online pake ini
- // http.begin("http://LoliconPC/REST_API/sensor"); // offline pake ini
- int httpCode = http.GET();
- if (httpCode > 0)
- {
- String json = http.getString(); //Get the request response payload
- const size_t bufferSize = JSON_OBJECT_SIZE(4) + 100;
- DynamicJsonBuffer jsonBuffer(bufferSize);
- JsonArray& root = jsonBuffer.parseArray(json);
- String kondisi = root[0]["kelembaban_tanah"];
- Serial.print("tingkat kelembaban : ");
- Serial.println(kondisi);
- http.end(); //Close connection
- }
- }
- void tanah_post(int kalib)
- {
- StaticJsonBuffer<300> JSONbuffer; //Declaring static JSON buffer
- JsonObject& JSONencoder = JSONbuffer.createObject();
- JSONencoder["user"] = user;
- JSONencoder["passwd"] = passwd;
- JSONencoder["no_key"] = no_key;
- JSONencoder["output_sensor"] = kalib;
- JSONencoder["letak"] = "B2";
- char JSONmessageBuffer[300];
- JSONencoder.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
- //Serial.println(JSONmessageBuffer);
- HTTPClient http; //Declare object of class HTTPClient
- http.begin("http://ferrynurr.000webhostapp.com/rest_json/kel_tanah");
- http.addHeader("Content-Type", "application/json");
- int httpCode = http.POST(JSONmessageBuffer); //Send the request
- if(httpCode > 0){
- String payload = http.getString(); //Get the response payload
- Serial.println(payload); //Print request response payload
- }else{
- Serial.println(http.errorToString(httpCode).c_str());
- }
- http.end(); //Close connection
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement