Blynk 2.0 cannot read string data from rx and tx pin

I am using Arduino Uno to read data from sensor and transfer the data to my esp8266 by using Rx and Tx pin, I have already tried reading the data in old Blynk app and everything is fine but I got problems in reading data from string in Blynk 2.0 for the data stream i have already changed it to string type . Thankyou

#define BLYNK_DEVICE_NAME "xxx"
#define BLYNK_AUTH_TOKEN "xxx"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
#define BLYNK_PRINT Serial

String data;
String I;

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "xxx";
char pass[] = "xxx";

BlynkTimer timer; 
#define DHTPIN 4          

#define DHTTYPE DHT11     
DHT dht(DHTPIN, DHTTYPE);

String sdata;                                                                                                                                                                                                                                                                                                                                                                                 
String myString; 
char rdata; 
#define 
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;
float Fahrenheit=0;

void myTimerEvent()
{
  Blynk.virtualWrite(V1, millis() / 1000);
  
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L,sensorvalue1); 
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  DS18B20.begin();
  timer.setInterval(1000L, getSendData);
  dht.begin();
  timer.setInterval(1000L, sendSensor);
    
}

void loop()
{
   if (Serial.available() == 0 ) 
   {
  Blynk.run();
  timer.run(); 

   }
   
  if (Serial.available() > 0 ) 
  {
    rdata = Serial.read(); 
    myString = myString+rdata; 
  
  }

}

void sensorvalue1()
{
sdata = myString ;
  Blynk.virtualWrite(V2,myString);
   myString = "";
}

You can’t re-use the same serial port like this.

You’ve included the SoftwareSerial library, but you aren’t using it to create a software serial port.

You have a function called myTimerEvent, but no timer to call it, and your other timers are set-up to clash every 1000ms.

But, most of all, I have to ask why you’re taking this approach to your hardware setup. It’s far from ideal.

Pete.

1 Like

I think you should keep your void loop() clear from everything except Blynk.run() and timer.run(). It’s standard practice when you’re Blynking.

It’s been ages since I did a project with Serial.read() because it gave me a headache :smiley: I think the syntax is String myString = String(myChar).

I solved my problems by using a timer that read from the serial buffer (by default it holds 64 bytes) once every second.

It is, of course, not the complete sketch he posted. If it was, I would be ranting about the 1 sec timer for the DHT sensor and the importance of reading the documentation and searching the forum! :face_with_raised_eyebrow: :joy: :kissing_heart:

2 Likes

ill improvise Thankyou

Thankyou ill improvise

Thank you, all working fine with this new code ( read serial data from arduino uno to esp8266)

#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
#include <OneWire.h>
#define BLYNK_PRINT Serial

                                                                                                                                                                                                                                                                                                                                                                                 
String myString; 
char rdata; 
String sdata;
String I;
float ph;
float temp;
float Fahrenheit=0;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "xxxi";
char pass[] = "xxx";



void myTimerEvent()
{

  Blynk.virtualWrite(V1, millis() / 1000);
  
}



void setup()
{
  // Debug console
  Serial.begin(9600); // make sure same baud bandwith with arduino uno

  Blynk.begin(auth, ssid, pass);

 timer.setInterval(1000L,sensorvalue1); 


}

void loop()
{
   if (Serial.available() == 0 ) 
   {
  Blynk.run();
  timer.run(); // Initiates BlynkTimer

   }
   
  if (Serial.available() > 0 ) 
  {
    rdata = Serial.read(); 
    myString = myString+rdata; 
  
  }

}

void sensorvalue1()
{
sdata = myString ;
 
  Blynk.virtualWrite(V2, sdata);
   myString = "";
}

@irfanzamry Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

1 Like

this is not my complete code only the serial data segment