Communicating two devices with different tokens

I have two esp32s running on the same template but has different device tokens. It was working well but the only issue was I can’t seem to access the other device’s sensor value history but the other one’s that are connected on the main esp board is working just fine. Example is that if I turn chart history into an hour ago history. It does not display the value, but if live reading it works fine. I used forward device data to sync the two esp boards. But I need to work the both out in a single device web dashboard in blynk that sync.

by the way this is the code, I haven’t tested the resending data through BLYNK_WRITE() and storing the data to another datastream but I hope this works.

/// JUST TEST THIS FIX FOR NOW

// for blynk ESP2 , FEB 09, 2024 3:51

#define BLYNK_TEMPLATE_ID "TMPL6-kTjpHlS"
#define BLYNK_TEMPLATE_NAME "AquaEasy Monitoring"
#define BLYNK_AUTH_TOKEN "hleI-MTUdjZQOGpFs3WLWRWjc-V1u8QI"

#define BLYNK_PRINT Serial

//install libraries
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BME280.h>
#include <ESP32Servo.h> // Library for Servo motor
#include <Wire.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "TP-Link_Extender";  // type your wifi name
char pass[] = "";  // type your wifi password

BlynkTimer timer; //import blynk timer function

int timedelay = 500;

#include <DFRobot_ESP_PH_WITH_ADC.h>

#define PH_PIN 34         // Analog pin for pH sensor
#define trigPin 25        //Set to GPIO 32
#define echoPin 26        //set to GPIO 33
#define servoPin 32       //Set to GPIO 35

#define VREF 3.3    //VREF (mv)
#define ADC_RES 4096 //ADC Resolution

#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701

long duration;
float distanceCm;
float distanceInch;

// pH sensor setup
DFRobot_ESP_PH_WITH_ADC ph;

//SET RELAY PINS
#define inlet_valve_relay 21
#define pump_out_relay 16

//define blynk switch variable
int mode = 0;
int inlet_switch = 0;
int pump_out_switch = 0;
//bool filter_switch = true;

int percentage_level;

float pHValue;


//VALVE = 8, SMALL PUMP = 9, FILTER = 7, MANUAL CONTROL = 10

BLYNK_WRITE(V10){
  mode = param.asInt();
}

BLYNK_WRITE(V8){
  inlet_switch = param.asInt();
  digitalWrite(inlet_valve_relay, inlet_switch);
}

BLYNK_WRITE(V9){
  pump_out_switch = param.asInt();
  digitalWrite(pump_out_relay, pump_out_switch);
}


int dissolved_resend;
int temp_resend;
int salinity_resend;


BLYNK_WRITE(V1){
  int dissolved_resend = param.asInt();
}

BLYNK_WRITE(V0){
  int temp_resend = param.asInt();
}

BLYNK_WRITE(V2){
  int salinity_resend = param.asInt();
}


void resend(){
  Blynk.virtualWrite(V13, dissolved_resend);

  Blynk.virtualWrite(V14, temp_resend);

  Blynk.virtualWrite(V15, temp_resend);
}

//Water Level
void ControlWaterLevel(){

  // pH reading
  float voltagePH = analogRead(PH_PIN) / 4096.0 * 3300;
  float phValue = ph.readPH(voltagePH, 25);

  ph.calibration(voltagePH, 25);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  
  // Calculate the distance
  distanceCm = duration * SOUND_SPEED/2;
  
  // Convert to inches
  distanceInch = distanceCm * CM_TO_INCH;

  int sonicdistance = 8;

  float percentage_level = 100 - ((distanceInch-4)/(sonicdistance))*100;

  if (mode == 1){
  }

  else{
    if (phValue < 7 && phValue > 8.5){
      if(percentage_level < 30){ // less than
          digitalWrite(inlet_valve_relay, HIGH);   // Turn on fill pump
          digitalWrite(pump_out_relay, LOW);   // Turn off drain pump
          delay(5000);  // Adjust the delay as needed for draining time
      } 
      else if (percentage_level > 90) { // more than
          digitalWrite(pump_out_relay, HIGH);   // Turn on fill pump
          digitalWrite(inlet_valve_relay, LOW);    // Turn off fill pump
          delay(5000);  // Adjust the delay as needed for filling time
      }
      else{
        digitalWrite(inlet_valve_relay,LOW);
        digitalWrite(pump_out_relay, LOW);
  
        Blynk.virtualWrite(V9, 0);
        Blynk.virtualWrite(V8, 0);

        delay(3000);
      }
    }
    else if (percentage_level < 95 && phValue >= 7 && phValue <=8.5){
        digitalWrite(inlet_valve_relay, HIGH);
        Blynk.virtualWrite(inlet_valve_relay, 1);   // Turn on fill pump
        delay(5000);
    }
    else{
        digitalWrite(inlet_valve_relay,LOW); // low
        digitalWrite(pump_out_relay, LOW); // low
        Blynk.virtualWrite(V9, 0);
        Blynk.virtualWrite(V8, 0);
        delay(5000);
    }
  }
}

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

  // pH sensor setup
  ph.begin();

  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output` 
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input

  pinMode(inlet_valve_relay, OUTPUT); // Sets the inlet as an Output`
  pinMode(pump_out_relay, OUTPUT); // Sets the pump as an Output`

  //SET INITIAL RELAY STATE AT O
  digitalWrite(inlet_valve_relay, inlet_switch);
  digitalWrite(pump_out_relay, pump_out_switch);

  Blynk.virtualWrite(V8,1); /// supposed to be low
  Blynk.virtualWrite(V9,1);
 
  Blynk.begin(auth, ssid, pass);

  //SET TIMEER INTERVAL FOR EACH FUNCTION EX.1000L
  timer.setInterval(5000L, sendPH);
  timer.setInterval(3000L, sendWaterLevel);
  //timer.setInterval(5000L, ControlWaterLevel);
  timer.setInterval(1000L, resend);

}

void sendPH(){
  // pH reading
  float voltagePH = analogRead(PH_PIN) / 4096.0 * 3300;
  float phValue = ph.readPH(voltagePH, 25);
  ph.calibration(voltagePH, 25);
  Blynk.virtualWrite(V3,phValue);
}

void sendWaterLevel(){
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  
  // Calculate the distance
  distanceCm = duration * SOUND_SPEED/2;
  
  // Convert to inches
  distanceInch = distanceCm * CM_TO_INCH;

  int sonicdistance = 8;

  float percentage_level = 100 - ((distanceInch-4)/(sonicdistance))*100;

  Blynk.virtualWrite(V4,percentage_level);
}

void loop(){
  
  //ControlWaterLevel();
  //8delay(5000);

  Blynk.run();
  timer.run();
}}```

That’s usually because you don’t have “Enable history data” turned-on for that datastream.

I don’t understand the rest of your post.

You should t be doing this in your void loop. You should read this…

Pete.

Yes, I’m gonna remove that now. I actually failed to mention that I used two separate device and I just sent the values in the device to the other using forward device data in automation part. The only problem was if I view the chart history I does not save.

as the only ones working fine was the values that from the main board, which i showed the code of.

I’m pretty sure that the datastream’s history is enabled tho.

I hope you understand it more this time. Thank you

Is there a go around with this. I’m actually planning to call it out using
BLYNK_WRITE(V){
int value = param.asInt()
}

then store it again

Blynk.virtualWrite(V,value)

like that…

but do you suggest anything more??

That does t achieve anything.

I’ll comment further when you post a screenshot confirming this.

Pete.

in cased you missed,

BLYNK_WRITE(V1){
  int dissolved_resend = param.asInt();
}

BLYNK_WRITE(V0){
  int temp_resend = param.asInt();
}

BLYNK_WRITE(V2){
  int salinity_resend = param.asInt();
}


void resend(){
  Blynk.virtualWrite(V13, dissolved_resend);

  Blynk.virtualWrite(V14, temp_resend);

  Blynk.virtualWrite(V15, temp_resend);
}

How is your automation set-up?

Which virtual pins are only showing live data with no history?

Pete.


this one is a sample of the automation set up for forwarding the data.

basically, the ones data forwarded through the forward device data automation does not work for the chart history only.


it’s like this, there are two devices ones the main and other ones sending data to the main one which I use to set up a dashboard for monitoring

So far you’re just talking in general terms about “virtual pins” without saying which specific pins you’re having an issue with, or saying that data on pin x on the main device is being forwarded to pin y on the secondary device.
Without this information, none of your code or screenshots makes no sense.

Pete.

i think this one gives the pins I have used. And they’re the pins I’m having issues with

BLYNK_WRITE(V1){
  int dissolved_resend = param.asInt();
}

BLYNK_WRITE(V0){
  int temp_resend = param.asInt();
}

BLYNK_WRITE(V2){
  int salinity_resend = param.asInt();
}


void resend(){
  Blynk.virtualWrite(V13, dissolved_resend);

  Blynk.virtualWrite(V14, temp_resend);

  Blynk.virtualWrite(V15, temp_resend);
}

and i’m using the same template. so basically it has the same name for pins for each other I just have to sync them up using the forward device data. I don’t know if it just does not really make sense or I’m just having a trouble explaining it

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

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

yes, thank you sir

No it doesn’t.

As I’ve said earlier, your void resend() function achieves nothing.

The only way to send data from one device to another is with an automation or using the HTTP(S) API.
You aren’t achieving this with void resend() and if you’re using the “resent” pins of V13, 14 & 15 to trigger automations then this could just as easily be achieved using original V0, V1 and V2 pins.

I cant help you unless you don’t provide the info I asked for.

Pete.

can you rephrase what you’re asking for sir?
And what is HTTP(S) API for ?

You have an automation, which I assume is triggered on “has changed” that forwards the data on device A virtual pin X to Device B, virtual pin Y

What are the virtual pin numbers for X and Y ?

Is “Enable data history” enabled for virtual pin Y ?

Pete.

I was using the same data pin number for each device to avoid confusion, for example I used V0 for temp on both of the ESP32s as they don’t have the same token.

I tried this and it does not work.

I for now is studying the HTTPS API method but can’t seem to grasp its concept and can’t find an example to work with it for the code application I need

Okay, so you’ve provided a screenshot of your V0 setup in post #4, but you’ve not provided a screenshot of the Superchart for the Temperature (V0) datastream on device AQUEASY VER2.

Can you confirm that this super hard doesn’t display historical data, only vice data?

I don’t think you’re ready for going down that route yet.

Pete.


this is an example in a live reading situation

but as soon as I get it to be viewed to last hour or so in chart history, it show ‘no data’.

btw, it is my last reply for the day, as blynk community limits user replies.

So one thing you’ve not clarified is the criteria that you used in your automation. Was it “has changed”?

Are the values shown in your temperature gauge changing, and do they match those on the device that is taking the readings?

Is this screenshot of your AQUEASY VER2 dashboard?

I’ve bumped-up your privileges, on the forum so that limit shouldn’t apply now.

Pete.