Device goes offline

Hi, i am adding the device with the quickstart template, it works. Then i change the testing code that blynk generates, pasting my code and device goes offline.
My hardware is TI MSP432+NodeMCU. I am getting everything on serial on nodemcu but when i try to upload it simly goes offline and the serial is not showing anything.

#define BLYNK_TEMPLATE_ID           "TMPLvNuI6u_g"
#define BLYNK_DEVICE_NAME           "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "M_JWokpG5OMGsLitRvyH6TNzpfYGDsgc"

#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <ArduinoJson.h>

#define BLYNK_PRINT Serial

SoftwareSerial nodemcu(D7,D8);
BlynkTimer timer; //announcing the timer
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "TheVoid";
char pass[] = "000000gggggg";
float temp, hum, pres, pt1, pt2, pt3, pt4;

void datareceive()
{
    StaticJsonBuffer<1024> JsonBuffer;
    JsonObject& data = JsonBuffer.parseObject(nodemcu);
    
//    if (data == JsonObject::invalid()) {
//      Serial.println("Invalid Json Object");
//      JsonBuffer.clear();
//      return;
//    }
    float temp = data["temperature"];
    float hum  = data["humidity"]   ;
    long  pres = data["pressure"]   ;
    float pt1  = data["pt1"]        ;
    float pt2  = data["pt2"]        ;
    float pt3  = data["pt3"]        ;
    float pt4  = data["pt4"]        ; 
}
void datasend()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
    Blynk.virtualWrite(V0, temp);
    Blynk.virtualWrite(V1, hum);
    Blynk.virtualWrite(V2, pres);
//    Blynk.virtualWrite(V3, pt1);
//    Blynk.virtualWrite(V4, pt2); 
//    Blynk.virtualWrite(V5, pt3); 
//    Blynk.virtualWrite(V6, pt4);  
}
void setup(){

    Serial.begin(115200);   
    Blynk.begin(auth, ssid, pass);
    nodemcu.begin(9600);
    // You can also specify server:
    //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
    //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

    // Setup a function to be called every second
    timer.setInterval(1500L, datareceive);
    timer.setInterval(3000L, datasend);
}

void loop(){

    
    Blynk.run();
    timer.run();

    
    }

I am keeping void loop clear, not flooding the cloud, internet is okay, credentials are okay, still offline.

Note that i am using json object to receive data from the MSP432 using software serial on NodeMCU at 9600. Maybe this has to do with the failure to connect again.

First of all, these need to be the first three lines of your sketch.

Secondly, I’d suggest that you clarify more about your hardware setup, physical connections, and what EXACTLY you mean by this…

Pete.

Firstly, thank you Mr Knight for answearing so fast. I edited the code above to be exactly like on my IDE
( i just used xxx to hide template and token in first post, as i did with wifi credential).

So, i have msp running and acquiring data from 5 sensors and these data are passed to NodeMCU through a json object using Software Serial (Rx, Tx).

SoftwareSerial nodemcu(D7,D8);

and

nodemcu.begin(9600);

This json objects gets cut into pieces (temp, hum…pt4);

StaticJsonBuffer<1024> JsonBuffer;
JsonObject& data = JsonBuffer.parseObject(nodemcu);

float temp = data["temperature"];
float hum  = data["humidity"]   ;
long  pres = data["pressure"]   ;
float pt1  = data["pt1"]        ;
float pt2  = data["pt2"]        ;
float pt3  = data["pt3"]        ;
float pt4  = data["pt4"]        ;

all of these i can print in nodemcu, which means data is okay until this point.
When i upload this, serial monitor does not even show that node is trying to connect to blynk.server.

I misread this. Applied and now the device is online. The datastreams though are not updated.

These variables are being re-declared within the datasend function, so the values you assign to them are only visible within the datasend function.

Remove all the “float” and the single “long” prefix which incidentally doesn’t match the variable type used in the global declarations…

and your sensor values should get sent to Blynk.

Pete.

1 Like

@PeteKnight
I declared the variables as globals. Tried datastreams as integer, double, string and changed the min and max but still no luck. Any idea? Is there a chance that declaring as float creates the problem? I also tried declaring the variables as string and got an error.

You had already done that, the problem is that you were then re-declaring them locally.

I’d suggest that you post your new sketch.

I’d also suggest that you add meaningful serial print messages at sensible points throughout your sketch so that you can see what the various variable values are at each stage.

Pete.


#define BLYNK_TEMPLATE_ID           "TMPLvNuI6u_g"
#define BLYNK_DEVICE_NAME           "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "M_JWokpG5OMGsLitRvyH6TNzpfYGDsgc"
#define BLYNK_PRINT Serial

#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <ArduinoJson.h>


SoftwareSerial nodemcu(D7,D8);
BlynkTimer timer; //announcing the timer

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "TheVoid";
char pass[] = "000000gggggg";
float temp, temp0, hum, pt1, pt2, pt3, pt4;
long pres;
void datareceive()
{
    Serial.println("datareceive starting...");
    StaticJsonBuffer<1024> JsonBuffer;
    JsonObject& data = JsonBuffer.parseObject(nodemcu);
    
    if (data == JsonObject::invalid()) {
      Serial.println("Invalid Json Object");
      JsonBuffer.clear();
      return;
    }
     temp = data["temperature"];
     hum  = data["humidity"]   ;
     pres = data["pressure"]   ;
     pt1  = data["pt1"]        ;
     pt2  = data["pt2"]        ;
     pt3  = data["pt3"]        ;
     pt4  = data["pt4"]        ;
    Serial.println("datareceive succeed");

}
void datasend()
{
      Serial.println("datasend starting...");
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
    //Blynk.virtualWrite(V0, temp);
//    Blynk.virtualWrite(V1, hum);
//    Blynk.virtualWrite(V2, pres);
//    Blynk.virtualWrite(V3, pt1);
//    Blynk.virtualWrite(V4, pt2); 
//    Blynk.virtualWrite(V5, pt3); 
//    Blynk.virtualWrite(V6, pt4);
    Serial.println(temp);  
    Serial.println("datasend succeed");
    Serial.println("---------------------");
}
void setup(){

    Serial.begin(115200);   
    Blynk.begin(auth, ssid, pass);
    nodemcu.begin(9600);
    // You can also specify server:
    //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
    //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

    // Setup a function to be called every second
    timer.setInterval(1500L, datareceive);
    timer.setInterval(3000L, datasend);
}

void loop(){

    
    Blynk.run();
    timer.run();

    
    }

and i get this in serial monitor:

Now, i know you may think it is a invalid Json object. But i commend out the lines:

Blynk.begin(auth, ssid, pass);
Blynk.run();

and my serial suddenly show the value the sensor is reading. Or to be exact, the parsing of the data object is right. The pattern of zeros and true readings relies on the timings of the two timers.


which makes me think the problem has to do with Json.parsing - timings of the timers - blynk communication as these 3 should be synchronized in a consecutive order?

Sorry for the details and the long post
Thanks in advance,
Gio.

EDIT: its seems like this is the line that causes conflict between the readings and not Blynk.run();

 Blynk.begin(auth, ssid, pass);

I’m unclear why you’re only trying to send every other set of readings to Blynk, but TBH your approach is extremely unconventional and impossible for others to recreate, so it’s something you’re just going to have to work out for yourself.

Pete.

i understand that, but how can Blynk.begin() mess up with my readings?
Also the title is wrong here, should i rename it? or mark as fixxed and start another thread?

It’s impossible to say without access to your hardware and full information about how your datastreams are configured and exactly how your hardware is connected, powered etc.

I doubt that creating a new topic will help much to be honest.

Pete.