cancel
Showing results for 
Search instead for 
Did you mean: 

Error in transferring data to NodeMCU from NucleoF401RE

LG.5
Associate II

Hiii,

Im trying to interface DHT11 sensor to NucleoF401RE and transfer the data via NodeMCU to Thingspeak

LG5_0-1710483886313.png

 

my dht11 code ran sucessfully

LG5_0-1710483674268.png

Also the NodeMCU code is flashed sucessfully and connected to Wifi

LG5_1-1710483740347.png

But Im not getting any data in Thingspeak

i got only two datas and the data transfer stopped

How to rectify this issue????

6 REPLIES 6
AScha.3
Chief II

Hi,

Why you dont connect the DHT direct on the NodeMCU ?

Then you can see, is your data coming there to "Thingspeak" or is there a problem in NodeMCU program.

If you feel a post has answered your question, please click "Accept as Solution".
LG.5
Associate II

Thanks for your reply

Even if I connect Dht11 directly to NodeMCU I'm not getting values in Thingspeak but the code is compiled successfully.What should I do now

Seems Thingspeak dont wanna speak with you. 🙂

1. debug-printf the DHT11 values , to see what you do+get.

2. send a fix info to Thingspeak , until you find out, how to show it - until this works.

3. then send the data from dht11 as you want.

If you feel a post has answered your question, please click "Accept as Solution".

@LG.5 wrote:

Thanks for your reply

Even if I connect Dht11 directly to NodeMCU I'm not getting values in Thingspeak 


So the problem is nothing to with the STM32.

You need a NodeMCU forum to discuss problems with your NodeMCU stuff - it's nothing to do with ST.

 


@LG.5 wrote:

but the code is compiled successfully. What should I do now


Just because code compiles successfully doesn't mean that it will actually do what you wanted - and, in this case, it clearly doesn't.

 


@LG.5 wrote:

What should I do now


You need to debug your code and/or your Thingspeak setup.

Here are some general tips on How To Debug:

https://www.avrfreaks.net/s/topic/a5C3l000000UaFXEA0/t153137?comment=P-1212908

 

 

LG.5
Associate II

Hii!

If i connect the DHT11 directly to NodeMCU its working fine and im getting values in Thingspeak

But if i try to send the data from NUCLEOF401RE to NodeMCU then null value is thrown in Thingspeak

WhatsApp Image 2024-03-15 at 10.46.54 PM.jpeg

#include <DHT.h>
#include <Wire.h>

#define DHTPIN PA1 // Replace with the actual pin connected to the DHT11 sensor
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
while (!Serial) {
delay(100);
}

Serial.println("STM32 DHTxx test!");

dht.begin();
}

void loop() {
delay(2000);

float humidity = dht.readHumidity();
float temperature = dht.readTemperature();

Serial.print("Temperature: ");
Serial.print(temperature, 1);
Serial.print(" °C, Humidity: ");
Serial.print(humidity, 1);
Serial.println("%");

// Check if temperature or humidity is high
if (temperature > 34.0 && humidity > 38.0) {
Serial.println("Disease Identified!");

// Send data to NodeMCU
Serial.print("Sending data to NodeMCU: ");
String data = String(temperature, 1) + "#" + String(humidity, 1) + "$";
Serial.println(data);

// Uncomment the next line if you want to send data to NodeMCU through Serial
// Serial1.println(data);
} else {
Serial.println("Conditions are normal.");
}

Serial.println();
delay(1500);
}

This is my DHT code

#include <ESP8266WiFi.h>
#include <ThingSpeak.h>

const char *ssid = "OPPO A55";
const char *password = "Sona2002#";
const char *thingSpeakApiKey = "L2UFGKXGO98IUE2S";
const unsigned long channelNumber = 2472082;

WiFiClient client; // Declare an instance of the WiFiClient class

void setup() {
Serial.begin(9600);
delay(10);

// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");

// Use the WiFiClient instance to initialize ThingSpeak
ThingSpeak.begin(client);
}

void loop() {
if (Serial.available() > 0) {
String data = Serial.readStringUntil('\n');
Serial.println("Received data from STM32: " + data);

// Split data into temperature and humidity
float temperature = data.substring(0, data.indexOf('#')).toFloat();
float humidity = data.substring(data.indexOf('#') + 1, data.indexOf('$')).toFloat();

// Update ThingSpeak channel with sensor readings
updateThingSpeak(temperature, humidity);
}
}

void updateThingSpeak(float temperature, float humidity) {
ThingSpeak.setField(1, temperature);
ThingSpeak.setField(2, humidity);

int status = ThingSpeak.writeFields(channelNumber, thingSpeakApiKey);

if (status == 200) {
Serial.println("ThingSpeak update successful");
} else {
Serial.println("Failed to update ThingSpeak");
}

delay(1000); // ThingSpeak update interval (in milliseconds)
}

This is my NodeMCU code 

Please help to rectify this issue

 


On 2024-03-15 04:00 AM, @LG.5 wrote:

Even if I connect Dht11 directly to NodeMCU I'm not getting values in Thingspeak

 


On 2024-03-15 09:49 PM, @LG.5 wrote:

Hii!

If i connect the DHT11 directly to NodeMCU its working fine and im getting values in Thingspeak

So you've now fixed your problem(s) with the NodeMCU sending to Thingspeak?

 


@LG.5 wrote:

But if i try to send the data from NUCLEOF401RE to NodeMCU then null value is thrown in Thingspeak


So what debugging have you done to find where the problem is?

  1. Is the Nucleo reading the sensor correctly?
  2. Is the Nucleo sending the readings correctly?
  3. Is the NodeMCU receiving the readings from the Nucleo?
  4. etc, etc, ...

It looks  like you're using a UART on the Nucleo to send to the NodeMCU - yes?

If so, you can test that what the Nucleo is sending by connecting it to a PC terminal.

Similarly, you can test that the NodeMCU is receiving by sending stuff to it from a PC terminal.

 

The thread I linked earlier contains a lot about debugging serial comms - read the whole thread:

https://www.avrfreaks.net/s/topic/a5C3l000000UaFXEA0/t153137

and follow the links...

Please give full details of how the the Nucleo is connected to the NodeMCU - a schematic of the wiring

Please use this button to properly post source code:

AndrewNeil_0-1710581732866.png