Hello Everyone,
I am experiencing something Strange. I send Data via ESPnow from an esp32 to 2 lilygo sim7000G modules. They both only have power hooked up and a micro sd card. The only difference between the two is that one has a SIM card.
Now, they both receive data and log it to an sd card no problem when I send it, but when I disconnect the Sim7000G WITHOUT the SIM card, the other keeps logging fine. If I disconnect the one WITH the SIM card, the other sim7000g barely logs any of the incoming data. When I plug the sim7000g WITH the Sim card back in it stays lagging until it connects to the APN and service and then its back to normal for both. What could be the problem? Here is the transmitter code being sent to them:
#include <esp_now.h>
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <Arduino.h>
#include "RTClib.h"
#include <esp_task_wdt.h>
#include <Preferences.h>
RTC_DS3231 rtc;
Preferences preferences;
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified();
//Pins for depth sensors (4 sensors)
#define TRIG1 13 //Module pins Depth sensor_1
#define ECHO1 12
//Depth_sensor_2
#define TRIG2 14
#define ECHO2 26
//Depth_senosr_3me
#define TRIG3 33
#define ECHO3 32
//Depth_sensor_4
#define TRIG4 25 //35 on board accidently in 1st design
#define ECHO4 27 // 34 on board accidently in 1st design
//Trigger Sonar Pins
#define TRIG5 4
#define ECHO5 2
bool myFlag = false; // Flag to indicate if a block should be resumed
//int distance_Measure1 = 0;
float distance_Measure1 = 0.0;
float distance_Measure2 = 0.0;
float distance_Measure3 = 0.0;
float distance_Measure4 = 0.0;
float distance_Measure5 = 0.0;
bool error;
float X_avg = 0.0;
float Y_avg = 0.0;
float Z_avg = 0.0;
//Time Variables
int previous_Sec = 0;
int Millis_Time = 0;
int C_millis = 0;
int P_millis = 0;
String time_now = "";
String time_now2 = "";
float temperatureF = 0.0;
//variables to keep track of the timing of 1 min for diferent packets to send
unsigned long start_time = 0;
unsigned long last_time = 0;
//Used inside main loop
unsigned long last_send_time = 0;
unsigned long cooldown_period = 0;
bool executeBlock = false;
//5 Minute Trigger Checking Time
unsigned long lastTriggerTime = 0;
//Counting for 3 consecutive readings
int consecutiveExceedCount = 0;
//Float to hold previous distance5
float previous_distance_Measure5 = 0.0;
//First Run depth5 Trigger comparison
bool firstRun = true;
// Define a variable to store the duration of main firing block in milliseconds
unsigned long durationMillis = 0;
// Flag to indicate if Rapid Fire mode is active
//bool rapidFireMode = false;
//Timer incase of Power Outage During Sending, etc.
//const unsigned long DELAY_TIME = 600000;
// REPLACE WITH YOUR RECEIVER MAC Address
//uint8_t broadcastAddress[] = {0x94, 0xB9, 0x7E, 0xE9, 0xBB, 0xAC};
//sim7000A Address = {0x4C, 0x75, 0x25, 0x67, 0x33, 0x14};
//simm7000G Address = {0x70, 0xB8, 0xF6, 0x06, 0xA5, 0xF8};
uint8_t broadcastAddress[] = {0x4C, 0x75, 0x25, 0x67, 0x33, 0x14};
uint8_t receiver2Address[] = {0x70, 0xB8, 0xF6, 0x06, 0xA5, 0xF8};
// Structure to send data from ESP32 using ESPNOW
// Must match the receiver structure
typedef struct struct_message {
float depth1;
float depth2;
float depth3;
float depth4;
float accel_x;
float accel_y;
float accel_z;
char TTime[15];
float Temp;
float Probe;
} struct_message;
struct struct_trigger {
boolean trigger;
float value1;
float value2;
};
// Create a struct_message called myData
struct_message myData;
struct_trigger myTriggers;
esp_now_peer_info_t peerInfo;
// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
// Serial.print("\r\nLast Packet Send Status:\t");
//Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
//if (!rapidFireMode) { //Will receive new values only if rapid fire is not enabled
memcpy(&myTriggers, incomingData, sizeof(myTriggers));
Serial.println("value 1 (from server) is now changed to: " + String(myTriggers.trigger));
Serial.println("value 2 (from server) is now changed to: " + String(myTriggers.value1));
Serial.println("value 3 (from server) is now changed to: " + String(myTriggers.value2));
if (myTriggers.value1 == 99 || myTriggers.value2 == 99) {
Serial.println("Resetting the device...");
ESP.restart();
}
}
void setup() {
Serial.begin(115200);
rtc.begin();
//rtc.adjust(DateTime(__DATE__, __TIME__));
//rtc.adjust(DateTime(0, 0, 0, 17, 36, 00)); // Set the desired time here
//delay(DELAY_TIME); //Delay incase of power outage during Sending, etc.
myTriggers.trigger = false; //Initial Pulse State of Trigger (Default)
myTriggers.value1 = 0.5; //3 consecutive reading values to start Rapid Firing (Default)
myTriggers.value2 = 24; //Running Time in Hours (Default)
consecutiveExceedCount = 0; //Default count
initWifi(); // Function to initialize WiFi
initESPNOW(); // Funtcion to initialize ESPNOW communication between ESP32
init_depth_Sensor(); // Initialize depth sensor
init_Accl_Sensor(); // Initialize Accel sensor
accel.setDataRate(ADXL345_DATARATE_3200_HZ); // Set the data rate to 3200 Hz (maximum)
esp_task_wdt_init(1200, true); //Watchdog reset after 20 minutes if frozen.
esp_now_register_recv_cb(OnDataRecv);
preferences.begin("my-app", false);
// Read the value from preferences
myFlag = preferences.getBool("flag", false);
myTriggers.trigger = preferences.getBool("trigger", false);
myTriggers.value1 = preferences.getFloat("value1", 0.5);
myTriggers.value2 = preferences.getFloat("value2", 24);
consecutiveExceedCount = preferences.getInt("exceedCount", 0);
// Print initial values
Serial.print("Initial value in preferences: ");
Serial.println(myFlag);
Serial.print("Initial trigger value in preferences: ");
Serial.println(myTriggers.trigger);
Serial.print("Initial value1 in preferences: ");
Serial.println(myTriggers.value1);
Serial.print("Initial value2 in preferences: ");
Serial.println(myTriggers.value2);
Serial.print("Initial consecutiveExceedCount in preferences: ");
Serial.println(consecutiveExceedCount);
Serial.println("\n Default My trigger for Probe Status True or False: ");
Serial.print(myTriggers.trigger);
Serial.println("\n Default 3x Depth Change to Fire value: ");
Serial.print(myTriggers.value1);
Serial.println("\n Default Fire time in Hours: ");
Serial.print(myTriggers.value2);
Serial.println("\n Default 3x Count Value: ");
Serial.print(consecutiveExceedCount);
}
void loop() {
// Reset the watchdog timer to prevent it from triggering if block isnt called after 20 min.
esp_task_wdt_reset();
unsigned long currentMillis = millis();
//if (myTriggers.trigger && !rapidFireMode) {
if (myTriggers.trigger) {
Trigger();
// if (myTriggers.trigger && !rapidFireMode && currentMillis - lastTriggerTime >= 2000) {
if (myTriggers.trigger && currentMillis - lastTriggerTime >= 2000) {
lastTriggerTime = currentMillis;
Serial.println("\n Probe is running successfully:");
MeasureTime2();
sendEspNowData();
Serial.println("\n Probe Depth: ");
Serial.print(distance_Measure5);
Serial.println("\n Previous Probe Depth: ");
Serial.print(previous_distance_Measure5);
Serial.println("\n Difference Between Depths: ");
Serial.print (abs(distance_Measure5 - previous_distance_Measure5));
Serial.println("\n Difference Counter Status (based on last reading): ");
Serial.print(consecutiveExceedCount);
Serial.println("\n Trying to find a difference of this number: ");
Serial.print(myTriggers.value1);
delay(30000); //Made 10-15 minutes for real implementation
}
// Check if the difference between consecutive readings of distance_measure5 exceeds myTriggers.value1
// When this block becomes true, stop worrying about probing above block and this block
//3 consecutive readings in 15 minutes greater than our sent value.
// if (!rapidFireMode && myTriggers.trigger) {
if (myTriggers.trigger) {
if (firstRun) {
firstRun = false;
} else {
if (abs(distance_Measure5 - previous_distance_Measure5) >= myTriggers.value1) {
consecutiveExceedCount++;
Serial.println("\n Probe Depth: ");
Serial.print(distance_Measure5);
Serial.println("\n Previous Depth: ");
Serial.print(previous_distance_Measure5);
} else {
consecutiveExceedCount = 0;
}
}
}
previous_distance_Measure5 = distance_Measure5;
// if (!rapidFireMode && consecutiveExceedCount >= 3) {
if (consecutiveExceedCount >= 1) { //Change back to 3 Here!!
Serial.println("\n 3 Consecutive Readings Found ");
Serial.println("\n Get ready for Rapid Fire! ");
Serial.println("\n Rapid Fire Run time in hours will be: ");
Serial.print(myTriggers.value2);
Serial.println("");
// delay(30000); //Delay in case there is anything on SD from last send above (Make 2 minutes here)
// Calculate the duration in milliseconds from value2 (hours to milliseconds conversion)
unsigned long durationHours = myTriggers.value2;
unsigned long durationMillis = durationHours * 3600000; // 1 hour = 3600000 milliseconds
preferences.begin("my-app", false); //Use or not??
// Change the value of myFlag to true
myFlag = true;
// Write the updated values back to preferences
preferences.putBool("flag", myFlag);
preferences.putBool("trigger", myTriggers.trigger);
preferences.putFloat("value1", myTriggers.value1);
preferences.putFloat("value2", myTriggers.value2);
preferences.putInt("exceedCount", consecutiveExceedCount);
// Print updated value
Serial.print("Updated value in preferences: ");
Serial.println(myFlag);
// Close the preferences handle
preferences.end();
delay(3000); // Wait for 3 seconds
// Record the current time before entering the loop
unsigned long blockStartTime = millis();
// Perform actions before entering the loop
MeasureTime2();
sendEspNowData();
if (myFlag) {
// Enter the loop and execute actions while within the specified duration
while (millis() - blockStartTime < durationMillis) {
Measure_Accleromter();
MeasureTime(); // Measure Time
executeBlock = true;
distance_Measure1 = 0;
distance_Measure2 = 0;
distance_Measure3 = 0;
distance_Measure4 = 0;
temperatureF = 0;
distance_Measure5 = 0; //probe send 0 here
sendEspNowData();
}
}
// Perform actions after exiting the loop
executeBlock = false;
MeasureTime2();
sendEspNowData();
delay(1000);
preferences.begin("my-app", false); //Use or not??
bool firstRun = false;
myFlag = false;
consecutiveExceedCount = 0;
myTriggers.trigger = false;
myTriggers.value1 = 0.5;
myTriggers.value2 = 24;
delay(1000);
// Write the updated values back to preferences
preferences.putBool("flag", myFlag);
preferences.putBool("trigger", myTriggers.trigger);
preferences.putFloat("value1", myTriggers.value1);
preferences.putFloat("value2", myTriggers.value2);
preferences.putInt("exceedCount", consecutiveExceedCount);
delay(1000);
// Print updated value
Serial.print("All Values and Preferences are defaulted!");
Serial.println("\n Flag is defaulted to: ");
Serial.println(myFlag); //should be 0
Serial.println("\n myTriggers.trigger is defaulted to: ");
Serial.println(myTriggers.trigger); //should be 0
Serial.println("\n myTriggers.value1 is defaulted to: ");
Serial.println(myTriggers.value1); //should be 0.5
Serial.println("\n myTriggers.value2 is defaulted to: ");
Serial.println(myTriggers.value2); //should be 24
Serial.println("\n consecutiveExceedCount is defaulted to: ");
Serial.println(consecutiveExceedCount); //should be 0
delay(1000);
// Close the preferences handle
preferences.end();
delay(1000);
}
} else if (!myTriggers.trigger && currentMillis - last_send_time >= 10000) {
last_send_time = currentMillis;
Serial.println("\n Sending No Flood Conditions Block: ");
Measure_Accleromter();
// executeBlock = false; /////??????????? Test and delete if not working
MeasureTime2();
Measure_Depth();
sendEspNowData();
// Add the delay here to wait for minutes before sending the next block
delay(10000); //300000 is good here to send every 5 min. //This delay affects the Trigger() start Time in above loop
}
}
////////////////////////////////////////////INITILIZATION OF FUNCTIONS///////////////////////////
//Function to initialze WiFi
void initWifi() {
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
}
//Function to initilaze ESPNOW communication
void initESPNOW() {
// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
// Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for Send CB to
// get the status of Trasnmitted packet
esp_now_register_send_cb(OnDataSent);
// Register peer
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
//Serial.println("Failed to add peer");
return;
}
//Register #2 peer
memcpy(peerInfo.peer_addr, receiver2Address, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println("Failed to add second peer");
return;
}
// Serial.println("ESPNOW initialize sucssfully");
}
// Function to initialize depth sensor
void init_depth_Sensor() {
pinMode(TRIG1, OUTPUT); // Initializing Trigger Output
pinMode(ECHO1, INPUT_PULLUP);
pinMode(TRIG2, OUTPUT); // Initializing Trigger Output and Echo Input
pinMode(ECHO2, INPUT_PULLUP);
pinMode(TRIG3, OUTPUT); // Initializing Trigger Output and Echo Input
pinMode(ECHO3, INPUT_PULLUP);
pinMode(TRIG4, OUTPUT); // Initializing Trigger Output and Echo Input
pinMode(ECHO4, INPUT_PULLUP);
pinMode(TRIG5, OUTPUT); // Initializing Trigger Output and Echo Input
pinMode(ECHO5, INPUT_PULLUP);
}
void TCA9548A(uint8_t bus)
{
Wire.beginTransmission(0x70); // TCA9548A address is 0x70
Wire.write(1 << bus); // send byte to select bus
Wire.endTransmission();
// Serial.print(bus);
}
// Function to initialize Accelerometer sensor
void init_Accl_Sensor(void) {
Wire.begin(); // Start wire library for I2C
Wire.beginTransmission(0x70);
error = Wire.endTransmission();
if (error == 0) {
// Serial.print("TCA9548A found at address 0x70");
} else {
Serial.println("No TCA9548A detected. Something went wrong!");
while (1);
}
// Initialize channel 1 to channel 6 of TCA9548A with ADXL345
for (int i = 1; i < 7; i++) {
TCA9548A(i);
if (!accel.begin()) {
Serial.println("No ADXL345 sensor detected.");
while (1);
} else {
Serial.print("ADXL345 sensor detected. : ");
Serial.print(i);
}
accel.setRange(ADXL345_RANGE_2_G);
displayRange();
// delay(10);
}
/*
// Initialize channel 7 for RTC
TCA9548A(7);
Wire.beginTransmission(0x68);
if (Wire.endTransmission() == 0) {
Serial.println ("RTC found on channel: 7");
rtc.begin();
rtc.adjust(DateTime(0, 0, 0, 15, 45, 00)); // Set the desired time here
DateTime now = rtc.now();
Serial.print("Current RTC Time: ");
Serial.print(now.hour());
Serial.print(":");
Serial.print(now.minute());
Serial.print(":");
Serial.println(now.second());
} else {
Serial.println("No RTC detected on channel 7.");
while (1);
}
*/
}
void displayRange(void)
{
Serial.print(" Range: +/- ");
switch (accel.getRange())
{
case ADXL345_RANGE_16_G:
Serial.print("16 ");
break;
case ADXL345_RANGE_8_G:
Serial.print("8 ");
break;
case ADXL345_RANGE_4_G:
Serial.print("4 ");
break;
case ADXL345_RANGE_2_G:
Serial.print("2 ");
break;
default:
Serial.print("?? ");
break;
}
Serial.println(" g");
}
/////////////////////////////////////////////////FUNCTION TO MEASURE SENSORS DATA///////////////////////////////////////
void MeasureTime() {
DateTime now = rtc.now();
int hr = now.hour();
int mn = now.minute();
int sec = now.second();
int current_sec = now.second();
if (current_sec == previous_Sec)
{
C_millis = millis();
Millis_Time = ( C_millis - P_millis );
if (Millis_Time >= 999)
{
P_millis = C_millis;
Millis_Time = random(998, 999);
}
}
else
{
previous_Sec = current_sec;
Millis_Time = 14;
P_millis = C_millis;
}
time_now = (String)Millis_Time;
//time_now = (String)hr + ":" + (String) mn + ":" + (String) sec + ":" + (String)Millis_Time;
// Serial.println("Time now: ");
//Serial.println(time_now);
// Serial.println();
float temperatureC = rtc.getTemperature();
temperatureF = (temperatureC * 9 / 5) + 32; // Convert Celsius to Fahrenheit
//Serial.print(" ");
// Serial.println(temperatureF);
// Serial.println();
}
void MeasureTime2() {
DateTime now = rtc.now();
int hr = now.hour();
int mn = now.minute();
int sec = now.second();
int current_sec = now.second();
if (current_sec == previous_Sec)
{
C_millis = millis();
Millis_Time = ( C_millis - P_millis );
if (Millis_Time >= 999)
{
P_millis = C_millis;
Millis_Time = random(998, 999);
}
}
else
{
previous_Sec = current_sec;
Millis_Time = 14;
P_millis = C_millis;
}
time_now2 = (String)hr + ":" + (String) mn + ":" + (String) sec + ":" + (String)Millis_Time;
//time_now = (String)hr + ":" + (String) mn + ":" + (String) sec + ":" + (String)Millis_Time;
// Serial.println("Time now: ");
//Serial.println(time_now);
// Serial.println();
float temperatureC = rtc.getTemperature();
temperatureF = (temperatureC * 9 / 5) + 32; // Convert Celsius to Fahrenheit
//Serial.print(" ");
// Serial.println(temperatureF);
// Serial.println();
}
void Trigger() {
distance_Measure5 = 0.0;
//sensor_5 calculation
digitalWrite(TRIG5, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG5, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(20);
digitalWrite(TRIG5, LOW); // Send pin low again
distance_Measure5 = pulseIn(ECHO5, HIGH, 26000); // Read in times pulse
distance_Measure5 = distance_Measure5 / 52 * 0.0328084, 2; //Convert the pulse duration to distance
}
// Function to measure depth
void Measure_Depth() {
distance_Measure1 = 0.0;
distance_Measure2 = 0.0;
distance_Measure3 = 0.0;
distance_Measure4 = 0.0;
//sensor_1 calculation
digitalWrite(TRIG1, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG1, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(20);
digitalWrite(TRIG1, LOW); // Send pin low again
distance_Measure1 = pulseIn(ECHO1, HIGH, 26000); // Read in times pulse
distance_Measure1 = distance_Measure1 / 13 * 0.0328084, 2; //Convert the pulse duration to distance
//delay(150);
//sensor_2 calculation
digitalWrite(TRIG2, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG2, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(20);
digitalWrite(TRIG2, LOW); // Send pin low again
distance_Measure2 = pulseIn(ECHO2, HIGH, 26000); // Read in times pulse
distance_Measure2 = distance_Measure2 / 13 * 0.0328084; //Convert the pulse duration to distance
//delay(150);
//sensor_3 calculation
digitalWrite(TRIG3, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG3, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(20);
digitalWrite(TRIG3, LOW); // Send pin low again
distance_Measure3 = pulseIn(ECHO3, HIGH, 26000); // Read in times pulse
distance_Measure3 = distance_Measure3 / 13 * 0.0328084; //Convert the pulse duration to distance
//delay(150);
//sensor_4 calculation
digitalWrite(TRIG4, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG4, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(20);
digitalWrite(TRIG4, LOW); // Send pin low again
distance_Measure4 = pulseIn(ECHO4, HIGH, 26000); // Read in times pulse
distance_Measure4 = distance_Measure4 / 13 * 0.0328084; //Convert the pulse duration to distance
//delay(150);
//13.4 for Water
//52 or 58 for air
/*
Serial.print("\n Distance (depth) by sensor_1: \n");
Serial.print(distance_Measure1);
Serial.println("cm");
Serial.print("\n Distance (depth) by sensor_2: \n");
Serial.print(distance_Measure2);
Serial.println("cm");
Serial.print("\n Distance (depth) by sensor_3: \n");
Serial.print(distance_Measure3);
Serial.println("cm");
Serial.print("\n Distance (depth) by sensor_4: \n");
Serial.print(distance_Measure4);
Serial.println("cm");
*/
//delay(50);
}
// Function to measure Accelerometer
void Measure_Accleromter(void)
{
X_avg = 0.0;
Y_avg = 0.0;
Z_avg = 0.0;
for (int i = 1; i < 7; i++) {
TCA9548A(i);
sensors_event_t event;
accel.getEvent(&event);
X_avg += event.acceleration.x;
Y_avg += event.acceleration.y;
Z_avg += event.acceleration.z;
}
// Need to measure time here
}
// Function to send data using ESPNOW
void sendEspNowData() {
// Serial.println("SendESPNowData Function: ");
float accel_x = X_avg / 6 ;
float accel_y = Y_avg / 6 ;
float accel_z = Z_avg / 6 ;
//buffer for converting float into string
// char depth1_string[8];
// memset(depth1_string, 0, 8);
// char depth2_string[8];
// memset(depth2_string, 0, 8);
// char depth3_string[8];
// memset(depth3_string, 0, 8);
// char depth4_string[8];
// memset(depth4_string, 0, 8);
// char accel_x_string[10];
// memset(accel_x_string, 0, 10);
// char accel_y_string[10];
// memset(accel_y_string, 0, 10);
// char accel_z_string[10];
// memset(accel_z_string, 0, 10);
// char temp_string[10];
// memset(temp_string, 0, 10);
//Convert float into string
// dtostrf(distance_Measure1, 6, 2, depth1_string);
// dtostrf(distance_Measure2, 6, 2, depth2_string);
// dtostrf(distance_Measure3, 6, 2, depth3_string);
// dtostrf(distance_Measure4, 6, 2, depth4_string);
// dtostrf(accel_x, 6, 5, accel_x_string);
// dtostrf(accel_y, 6, 5, accel_y_string);
// dtostrf(accel_z, 6, 5, accel_z_string);
// dtostrf(temperatureF, 6, 2, temp_string);
char time_NOW[15];
time_now.toCharArray(time_NOW, 15); //millis sending only
char time_NOW2[15];
time_now2.toCharArray(time_NOW2, 15); //total time sending
// sprintf(time_NOW, "%c", time_now);
// Serial.println("time_NOW___");
// Serial.println(time_NOW);
myData.depth1=distance_Measure1;
myData.depth2=distance_Measure2;
myData.depth3=distance_Measure3;
myData.depth4=distance_Measure4;
myData.accel_x=accel_x;
myData.accel_y=accel_y;
myData.accel_z=accel_z;
myData.Temp=temperatureF;
myData.Probe=distance_Measure5;
if (executeBlock) {
// Assign time_now2 to myData.TTime during the block execution
strcpy(myData.TTime, time_NOW);
} else {
// Assign time_now to myData.TTime outside the block execution
strcpy(myData.TTime, time_NOW2);
}
//Serial.println("\n Its sending this block for Printing purposes: ");
//Serial.println("\n myData.depth_1 is: ");
// Serial.println(myData.depth1);
// Serial.println("\n myData.depth_2 is: ");
// Serial.println(myData.depth2);
// Serial.println("\n myData.depth_3 is: ");
// Serial.println(myData.depth3);
// Serial.println("\n myData.depth_4 is: ");
// Serial.println(myData.depth4);
// Serial.println("\n Probe Trigger Depth is: ");
// Serial.println(distance_Measure5);
// Serial.println("\n myData.accel_x is: ");
Serial.println(myData.accel_x, 4);
// Serial.println("\n myData.accel_y is: ");
Serial.println(myData.accel_y, 4);
// Serial.println("\n myData.accel_z is: ");
Serial.println(myData.accel_z, 4);
// Serial.println("\n myData.TTime is: ");
Serial.println(myData.TTime);
// Serial.println("\n myData.Temp is: ");
// Serial.println(myData.Temp);
// Serial.println("\n myData.Probe is: ");
// Serial.println(myData.Probe);
// Send message to the firsto receiver
esp_err_t result1 = esp_now_send(broadcastAddress, (uint8_t*)&myData, sizeof(myData));
if (result1 == ESP_OK) {
// Serial.println("Sent to the first receiver with success");
} else {
// Serial.println("Error sending data to the first receiver");
}
// Send message to the second receiver
esp_err_t result2 = esp_now_send(receiver2Address, (uint8_t*)&myData, sizeof(myData));
if (result2 == ESP_OK) {
// Serial.println("Sent to the second receiver with success");
} else {
// Serial.println("Error sending data to the second receiver");
}
}