Go Down

Topic: PUT request with ESP8266 + NodeMCUv3 with JSON data to NodeJS server (local net) (Read 167 times) previous topic - next topic

MuscleUpUp

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:

Code: [Select]

#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

zoomkat

Below is a forum search for "ESP8266 put" that might have some info. You can check the various code postings to see what libraries are being used in the code. Some of the issues might be the same as yours.


https://www.google.com/search?ie=UTF-8&oe=UTF-8&q=ESP8266+put&domains=https%3A%2F%2Fforum.arduino.cc&sitesearch=https%3A%2F%2Fforum.arduino.cc#spf=1575784623937
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

MuscleUpUp

Below is a forum search for "ESP8266 put" that might have some info. You can check the various code postings to see what libraries are being used in the code. Some of the issues might be the same as yours.


https://www.google.com/search?ie=UTF-8&oe=UTF-8&q=ESP8266+put&domains=https%3A%2F%2Fforum.arduino.cc&sitesearch=https%3A%2F%2Fforum.arduino.cc#spf=1575784623937
Sorry but that doesnt help at all

Go Up