serial interface between uno+nodemcu ,cloud data

Hellow i interfaced the arduino uno with temperature sensor and sending it to node mcu.i want to send these data with cloud by using node mcu ,the serial data received is accurate ,but there is some mistake for uploding these data to node mcu cloud code…
the reading of data for cloud is not working,

my arduino code is like these,

const int lm35_pin = A5;

void setup(void) {

Serial.begin(115200);

}

void loop(void) {

int temp_adc_val;
float temp_val;
float value;
temp_adc_val = analogRead(lm35_pin);
temp_val = (temp_adc_val * 4.88);
value = (temp_val / 10);

Serial.println(value);

delay(1000);
}

my node mcu code are like these…

#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#define WIFI_SSID “spree@me”
#define WIFI_PASSWORD “1234abcd”

#define TOKEN “m3lUe0NiI6nz6ZiLwjU6”
char cloudServer = “demo.thingsboard.io”;

WiFiClient wifiClient;
PubSubClient client(wifiClient);

unsigned long lastSend;
int dat;
void setup()
{
Serial.begin(115200);

delay(10);
InitWiFi();
client.setServer(cloudServer, 1883);
lastSend = 0;
}

void loop()
{
if ( !client.connected())
{
reconnect();
}

if ( millis() - lastSend > 1000 )
{
temperature_humidity();
lastSend = millis();
}

client.loop();
}

void temperature_humidity()
{
if (Serial.available()){
dat = Serial.read();
Serial.write(dat);
}
String temperature = String(dat);
String payload = “{”;
payload += ““temperature”:”;
payload += temperature;
payload += “}”;

char attributes[100];
payload.toCharArray( attributes, 100 );
client.publish( “v1/devices/me/telemetry”, attributes );
Serial.println( attributes );
}
void InitWiFi()
{
Serial.println(“Connecting to AP …”);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(“Connected to AP”);
}

void reconnect()
{
while (!client.connected())
{

if ( WiFi.status() != WL_CONNECTED)
{
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(“Connected to AP”);
}
//Serial.print(“Connecting to CLOUD …”);
// Attempt to connect (clientId, username, password)
if ( client.connect(“ESP8266 Device”, TOKEN, NULL) ) {
//Serial.println( “[DONE]” );
} else {
Serial.print( “[FAILED] [ rc = " );
Serial.print(client.state());
Serial.println( " : retrying in 5 seconds]” );

delay( 5000 );
}
}
}

kolhapurkar:
the serial data received is accurate ,but there is some mistake for uploding these data to node mcu cloud code…

That reads as if the communication between the Arduino and the NodeMCU is working and your problem is with programming the NodeMCU to send the data onwards. Is that correct?

…R

PS … To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

my arduino uno code is,

const int lm35_pin = A5;

void setup(void) {
  Serial.begin(115200);

  }


void loop() {
 
  int temp_adc_val;
  float temp_val;
  float value;
  temp_adc_val = analogRead(lm35_pin);
  temp_val = (temp_adc_val * 4.88);
  value = (temp_val / 10);

  Serial.println("Temperature :");
  Serial.println(value);

  delay(1000);

my node mcu code are like these…

#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#define WIFI_SSID        "Vaahaka@321"
#define WIFI_PASSWORD    "vaahaka@22018"

#define TOKEN "m3lUe0NiI6nz6ZiLwjU6"
char cloudServer[] = "demo.thingsboard.io";

WiFiClient wifiClient;
PubSubClient client(wifiClient);

unsigned long lastSend;
int dat;
void setup()
{
  Serial.begin(115200);

  delay(10);
  InitWiFi();
  client.setServer(cloudServer, 1883);
  lastSend = 0;
}

void loop()
{
  if ( !client.connected())
  {
    reconnect();
  }

  if ( millis() - lastSend > 1000 )
  {
    temperature_humidity();
    lastSend = millis();
  }

  client.loop();
}

void temperature_humidity()
{
  if (Serial.available()){
  dat = Serial.read();
  Serial.write(dat);
}
  String temperature = String(dat);
  String payload = "{";
  payload += "\"temperature\":";
  payload += temperature;
  payload += "}";


  char attributes[100];
  payload.toCharArray( attributes, 100 );
  client.publish( "v1/devices/me/telemetry", attributes );
  Serial.println( attributes );
}
void InitWiFi()
{
  Serial.println("Connecting to AP ...");

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to AP");
}

void reconnect()
{
  while (!client.connected())
  {

    if (  WiFi.status() != WL_CONNECTED)
    {
      WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
      while (WiFi.status() != WL_CONNECTED)
      {
        delay(500);
        Serial.print(".");
      }
      Serial.println("Connected to AP");
    }
    //Serial.print("Connecting to CLOUD ...");
    // Attempt to connect (clientId, username, password)
    if ( client.connect("ESP8266 Device", TOKEN, NULL) ) {
      //Serial.println( "[DONE]" );
    } else {
      Serial.print( "[FAILED] [ rc = " );
      Serial.print(client.state());
      Serial.println( " : retrying in 5 seconds]" );

      delay( 5000 );
    }
  }
}

kolhapurkar: my node uno code is,

Thanks.

Now what about answering my question?

...R

sorry, I did by mistake and now I corrected it..

kolhapurkar: I did by mistake and now I corrected it..

I don't understand.

In Reply #1 I asked you

That reads as if the communication between the Arduino and the NodeMCU is working and your problem is with programming the NodeMCU to send the data onwards. Is that correct?

...R

My problem is how exactly the data read and use for sending on cloud...

I read data serially by connecting tx and rx by after adding it program for process become difficult...

So please give me idea what to use in above program to solve the use of data...

kolhapurkar:
My problem is how exactly the data read and use for sending on cloud…

I read data serially by connecting tx and rx by after adding it program for process become difficult…

So please give me idea what to use in above program to solve the use of data…

I don’t understand your problem and you have not answered the question I asked you in order to help me understand it.

Think about it like this …

Can you send data from the Arduino to the NodeMCU and view that data from the NodeMCU on the Arduino Serial Monitor?

…R

sorry bro, for not cogency ,

yes I want to send temperature data from arduino uno to Nodemcu by serial transmission and at the same moment the received data fetch to cloud .

my problem is that data is received in the Nodemcu but I unable to use it for data fetch.the serial transmission is ok.

and one more is that i want the data to be received by Nodemcu on serial monitor with received data on cloud should be same..

mean that both cloud and Nodemcu data should be same .

so that I will confirm by then the received data is correct.

In the above program what i will do for receive data and at the same time I fetch them on cloud in Nodemcu programming.

thats it.......

kolhapurkar: my problem is that data is received in the Nodemcu but I unable to use it for data fetch

OK. So you have some data in your Nodemcu but you don't know how to send that to a web server somewhere.

Post an example of the data that you want the Nodemcu to send

Also provide details of the format of message that the webserver requires.

Do you know how to send a similar message to the web server using a program on your PC.

My suggestion is to start with a simple program for the Nodemcu that just sends a fixed message

...R

Robin2: OK. So you have some data in your Nodemcu but you don't know how to send that to a web server somewhere.

Post an example of the data that you want the Nodemcu to send

the code is in the original post. he uses PubSubClient library. that is why I didn't pick this thread. I have no experience with MQTT.

Juraj: the code is in the original post. he uses PubSubClient library. that is why I didn't pick this thread. I have no experience with MQTT.

Neither have I.

I read the Title as meaning that he was having trouble sending the data from the Arduino to the Nodemcu. Eventually we seem to have confirmed that that part works fine.

...R

Robin2: Neither have I.

I read the Title as meaning that he was having trouble sending the data from the Arduino to the Nodemcu. Eventually we seem to have confirmed that that part works fine.

...R

for now. a byte after a second. but if it is an analog sensor...

Juraj: for now. a byte after a second. but if it is an analog sensor...

Getting useful info from the OP is very difficult.

...R