Skip to main content
Visitor II
March 15, 2024
Question

Error in transferring data to NodeMCU from NucleoF401RE

  • March 15, 2024
  • 3 replies
  • 1618 views

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????

    This topic has been closed for replies.

    3 replies

    Super User
    March 15, 2024

    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.

    LG.5Author
    Visitor II
    March 15, 2024

    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

    Super User
    March 15, 2024

    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.

    LG.5Author
    Visitor II
    March 16, 2024

    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

    Super User
    March 16, 2024

     


    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