Esp32 to node-red get request

Hello i am trying to make get request from esp32 to node red, I have managed to make a successful request but I am only receiving empty
image
this my simple node red Flow:
image
and this my esp32code:

#include <SPI.h>
#include <HttpClient.h>
#include <Ethernet.h>
#include <EthernetClient.h>


// This example downloads the URL "http://arduino.cc/"
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
// Name of the server we want to connect to
const char kHostname[] = "3.145.1.222";
// Path to download (this is the bit after the hostname in the URL
// that you want to download
const char kPath[] = "/data";

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Number of milliseconds to wait without receiving any data before we give up
const int kNetworkTimeout = 30*1000;
// Number of milliseconds to wait if no data is available before trying again
const int kNetworkDelay = 1000;
void setup()
{
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
  Ethernet.init(5);
  while (Ethernet.begin(mac) != 1)
  {
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(15000);
  }  
}

void loop()
{
  Serial.println("Hello wo");
  int err =0;
  EthernetClient client;
  HttpClient http(client);
  err = http.get(kHostname,
             1880, 
             kPath,
             NULL);
  if (err == 0)
  {
    Serial.println("startedRequest ok");
  }
  String temperature = "44";
  String requestBody = "{\"temperature\":\"" + temperature + "\"}";
  int contentLength = requestBody.length();
  char contentLenght[] = "21";
  char c[] = "{\"temperature\":\"44\"}";
  http.sendHeader("Content-Type", "application/json");
  http.sendHeader("Content-Length", String(contentLength).c_str());
  http.sendHeader("");
  http.print(requestBody);
  Serial.println(http.responseStatusCode());
  delay(10000);
}

Hey!!

You are probably posting your issue in the wrong channel, as this for the Arduino IoT Cloud.

As we are in this channel, let me suggest that, what you are trying to do, is very simple using the IoT Cloud.
You can choose several variables that are automatically synced with the IoT Cloud and you can use the platform's API to retrieve that information. So no need to implement the HTTP server or client in the board itself which is far more complicated.
Some information about the IoT Cloud

Additionally, if you want to use the data in node-red, there are Arduino IoT Cloud nodes that you can use. More information here:

I hope this helps.

1 Like

I have moved your topic to a more appropriate forum category @hjeij2000.

In the future, please take some time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.