Hello,
I am trying to send data from my light sensor using ESP8266 and update "value" of a sensor in my server.
Unfortunately, I was working on that many hours but nothing works for me...
Reading data from a sensor and connecting to the network is done and works.
The code which is intresting to us:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include "ArduinoJsonv6.cpp"
#include <WiFiClient.h>
// Server parameters
const char* Server_ID = "192.168.1.32";
const int port = 8080;
String URL = "/pi/Rooms/LivingRoom/sensors/Light/5dec517737d254014be8f766"; //ID of the sensor
void loop() {
// Reading data from the sensor
unsigned long Lux;
String Lux_string = "";
tsl.TSL2581_Read_Channel();
Lux = tsl.calculateLux(2, NOM_INTEG_CYCLE);
Read_gpio_interrupt(2000, 50000);
delay(50);
StaticJsonDocument<200> doc;
doc["value"] = Lux;
serializeJson(doc, Serial);
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
http.begin(Server_ID + ":" + port + URL); // (1) How can I pass here my parameters?
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.PUT(HOW CAN I PASS HERE MY JSON - DOC???); // (2) Passing here the json is like black magic...
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
http.end();
delay(5000);
}
}
Main problems:
(1) - how to pass to http.begin my server parameters?
(2) - passing my json to PUT request - it seems to be very simple but it isnt.
if someone can solve that problem with other library it also good solution for me. Unfortunately,
on each website there is a solution which uses a different library, it is very confusing.
Thanks for any kind of help