Why my data don't show on superchart?

hi guys…

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
SoftwareSerial hm10(D5,D6); //RX, TX 연결
BlynkTimer timer;
char auth[] = "++";
int data;


char ssid[] = "ee";
char pass[] = "20";

void myTimerEvent()
{Blynk.virtualWrite(V0,data/100);
 Blynk.virtualWrite(V1,data%100);} 
 
void setup() {
 
  Serial.begin(9600);
  hm10.begin(9600);
  
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L,myTimerEvent); 
}


void loop() {
  Blynk.run();
  timer.run();
  
  if(hm10.available()){
    int data=hm10.read();
    Serial.write(data);

  }
  if(Serial.available()){

    byte data=Serial.read();
    hm10.write(data);
  }
   
}



i get data from bluetooth in loop and i want to show that data on blynk. but it’s not showing… can you tell me why?
i used nodemcu

You’re declaring data as a local variable in your void loop, so it’s not available in your myTimerEvent function. if you declare it at the top of your code it will be global, so available to any function. If you don’t understand the concept of variable scope then google it to find out more.

Also, you may find that having this code in your void loop:

could cause you problems with Blynk disconnections.

Pete.

i change my code as you said but it block my bluetooth connect . and i don’t know why TT

#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
SoftwareSerial hm10(D5,D6); //RX, TX 연결
BlynkTimer timer;
char auth[] = "9d8333";

int data=hm10.read();


char ssid[] = "uest";
char pass[] = "2020";

void myTimerEvent()
{Blynk.virtualWrite(V0,data/100);
 Blynk.virtualWrite(V1,data%100);} 
 
void setup() {
 
  Serial.begin(9600);
  hm10.begin(9600);
  
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L,myTimerEvent);
}


void loop() {
  Blynk.run();
  timer.run();
  
  if(hm10.available()){
    Serial.write(data);
     }
  if(Serial.available()){
    
    hm10.write(data);
  }
   
}

and i need void loop part coding to connect bluetooth so i can’t remove it

I didn’t say that you should move this line to the top of your code:

int data=hm10.read();

I said that you should declare the variable “data” at the top of your code and not re-declare it locally every time void loop runs.
I’d fix it for you. except that things are worse than I originally thought because you’re also re-declaring the same variable as a byte variable type later on in your void loop.

Google variable scope for Arduino and/or look at some of the coding examples in sketch builder so that you understand how to declare a global variable then re-use it art various places within your code without re-declaring it.

I realise why it’s there, but it may cause Blynk disconnection issues and you should be aware of that.

Pete.

1 Like

thank you for your reply. i’ll try ya!