Pass float values using bridge widget

Hi members:

I’m doing a simple project passing two float values: temperature and humidity from BME280 esp8266 master device to micro-OLED slave esp8266 device. I’m confusing with the BLYNK_WRITE function. I got core dump message during the slave execution. Please help me debugging.

/*Master code*/

/*   -BME280-
   5V - VCC
   GND - GND
   D1  - SCL
   D2  - SDA

*/

#include <ESP8266WiFi.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25) 

char ssid[] = "blahblahblah1";
char pass[] = "blahblahblah2";
char LocalAuthToken[] = "blahblahblah4";
char RemoteAuthToken[] = "blahblahblah3";

WidgetBridge bridge1(V1);
WidgetBridge bridge2(V2);

Adafruit_BME280 bme;

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

  Serial.println("Connecting wifi");
  Blynk.begin(LocalAuthToken, ssid, pass);  
  while (Blynk.connect() == false);
  bridge1.setAuthToken(RemoteAuthToken); 
  bridge2.setAuthToken(RemoteAuthToken); 
  bool status;
  status = bme.begin(0x76);  
  if (!status) {
     Serial.println("Could not find a valid BME280 sensor, check wiring!");
     while (1);
  }

}

void loop() {
  Blynk.run();

  //------get data from BME280------
    blynkupdate();
}

void blynkupdate() {
  bridge1.virtualWrite(V1, bme.readTemperature());
  bridge2.virtualWrite(V2, bme.readHumidity());
}
/*Slave Code*/

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

#define PIN_RESET -1
#define DC_JUMPER 0

char ssid[] = "blahblahblah1";
char pass[] = "blahblahblah2";
char RemoteAuthToken[] = "blahblahblah3";
char LocalAuthToken[] = "blahblahblah4";

MicroOLED oled(PIN_RESET, DC_JUMPER);

WidgetBridge bridge1(V1);
WidgetBridge bridge2(V2);

float value1, value2;

BLYNK_WRITE(V1) 
{
  value1=param.asFloat(); 
}

BLYNK_WRITE(V2) 
{
  value2=param.asFloat(); 
}

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

  Serial.print("Connecting:");
  Serial.println(ssid);
  Blynk.begin(LocalAuthToken, ssid, pass);   //start blynk
  while (Blynk.connect() == false);
  bridge1.setAuthToken(RemoteAuthToken); 
  bridge2.setAuthToken(RemoteAuthToken); 
  Blynk.syncAll();
}

void loop() {
  Serial.print("Temp="); Serial.println(value1); 
  Serial.print("Humi="); Serial.println(value2);   
  display_update();
}

void display_update() {
  //------Update OLED------
  oled.clear(PAGE); oled.setFontType(0);
  oled.setCursor(0,  0); oled.print(value1);
  oled.setCursor(0, 32); oled.print(value2);
  oled.display();
}
19:08:49.754 -> Connecting wifi
19:08:56.605 -> Temp=0.00
19:08:56.605 -> 
19:08:56.605 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
19:08:56.652 -> 
19:08:56.652 -> Exception (28):
19:08:56.652 -> epc1=0x40203d32 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
19:08:56.652 -> 
19:08:56.652 -> >>>stack>>>
19:08:56.652 -> 
19:08:56.652 -> ctx: cont
19:08:56.652 -> sp: 3ffffda0 end: 3fffffc0 offset: 0190
19:08:56.652 -> 3fffff30:  3ffe8521 3ffee990 3ffee990 40203c8c  
19:08:56.652 -> 3fffff40:  3ffe852c 000000b0 3ffee990 402037f1  
19:08:56.652 -> 3fffff50:  40204294 00000000 3ffee990 40203876  
19:08:56.652 -> 3fffff60:  402076ac 3ffee990 3ffe8518 40203962  
19:08:56.652 -> 3fffff70:  3fffdad0 00000000 3ffee990 3ffeecd4  
19:08:56.652 -> 3fffff80:  3fffdad0 00000000 3ffee990 40201130  
19:08:56.652 -> 3fffff90:  40207950 00000000 3ffeeba8 4020117a  
19:08:56.698 -> 3fffffa0:  feefeffe 00000000 3ffeec94 40204eec  
19:08:56.698 -> 3fffffb0:  feefeffe feefeffe 3ffe86d8 40100f29  
19:08:56.698 -> <<<stack<<<
19:08:56.698 -> 
19:08:56.698 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
19:08:56.698 -> 
19:08:56.698 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,7)
19:08:56.698 -> 
19:08:56.698 -> load 0x4010f000, len 3584, room 16 
19:08:56.698 -> tail 0
19:08:56.698 -> chksum 0xb0
19:08:56.698 -> csum 0xb0
19:08:56.698 -> v2843a5ac
19:08:56.698 -> ~ld

@chatr 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:
```

Also, when you are posting serial monitor output it’s much better to copy the contents of your serial monitor and paste it into your forum post, once again using triple backticks at the beginning and end.

Pete.

1 Like

Okay, there are so many things wrong with your code that it’s difficult to know where to start.
This error:

usually occurs when you try to access a variable or pointer that is outside of the legal bounds.
My guess is that this line:

is the culprit, as I believe that acceptable values are 0 or 1, and the -1 value is out of bounds.

You clearly don’t understand how Bridge code works. In the scenario you’ve explained, you ONLY need to run the Bridge code on your master device, as you are only sending data from the master to the slave.

I don’t understand why you’ve declared two bridges:

When only one should be needed two send data on V1 and V2 to a single slave device.

Having blynkupdate(); in your void loop breaks all of the rules of Blynk programming, as the blynkupdate() function contains virtualWrite commands which will flood the Blynk server with data, and ultimately lead to you being disconnected.
You should use a timer to call the blynkupdate() function, as described here:

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

The same applies to the code you have in the void loop of your slave sketch (which incidentally is missing Blynk.run();), although in this case this code doesn’t need be called with a timer, it needs to be in your BLYNK_WRITE(vPin)` callbacks so that the display is updated when a new value arrives on either of the virtual pins.

The Blynk.syncAll(); command in your slave void setup is a waste of time, you should remove it.

Your slave void setup appears to be missing an oled.begin(); command.

There may be more issues with the two sketches, but they are the ones that leap out at me.

Pete.

1 Like

Also no Blynk.run() in the slave code.

1 Like