My apologies up-front if this has already been discovered or explained. I have tried to do my homework in the forum in advance of this posting and a reference to this behaviour did not jump out to me.
I have a Xenon and Argon as part of a mesh network. The Xenon reads a temp every 10 seconds and sends via a Mesh.publish() to the Argon. The Argon displays the temp received on an OLED.
My Xenon will need to be battery powered so sleeping for 1 minute and then taking a reading is my desired end goal but I realize sleep is not yet implemented, so the best I can do for now is turn off the radios for that minute and then bring them back online to send the reading.
The following code does not work. ie. no message is received by the Argon, however, by adding a small delay of say 5ms after detecting Mesh.ready() it appears to work flawlessly.
Note I add a counter to the temp just to easily see that the temp was updated on the Argon so there for debug purposes only.
Code which fails:
SYSTEM_MODE(MANUAL);
#include "MCP9808.h"
MCP9808 mcp = MCP9808();
const long interval = 10 * 1000;
unsigned long previousTime = 0;
char buffer[100];
void setup() {
pinMode(D4, OUTPUT);
// Use external antenna
digitalWrite(ANTSW1, 0);
digitalWrite(ANTSW2, 1);
while (! mcp.begin()) {
delay(500);
}
}
uint8_t count = 0;
float temp;
void loop() {
unsigned long currentTime = millis();
if ( currentTime - previousTime >= interval) {
previousTime = currentTime;
Mesh.on();
Mesh.connect();
waitUntil(Mesh.connecting);
waitUntil(Mesh.ready);
temp = mcp.getTemperature() + count;
count++;
snprintf(buffer, sizeof(buffer), "%2.1f", temp);
Mesh.publish("newTemp", buffer);
Mesh.off();
digitalWrite(D4, HIGH);
delay(1000);
digitalWrite(D4, LOW);
}
}
Adding delay(5) after WaitUntil(Mesh.ready) works perfectly.
SYSTEM_MODE(MANUAL);
#include "MCP9808.h"
MCP9808 mcp = MCP9808();
const long interval = 10 * 1000;
unsigned long previousTime = 0;
char buffer[100];
void setup() {
pinMode(D4, OUTPUT);
// Use external antenna
digitalWrite(ANTSW1, 0);
digitalWrite(ANTSW2, 1);
while (! mcp.begin()) {
delay(500);
}
}
uint8_t count = 0;
float temp;
void loop() {
unsigned long currentTime = millis();
if ( currentTime - previousTime >= interval) {
previousTime = currentTime;
Mesh.on();
Mesh.connect();
waitUntil(Mesh.connecting);
waitUntil(Mesh.ready);
temp = mcp.getTemperature() + count;
count++;
delay(5);
snprintf(buffer, sizeof(buffer), "%2.1f", temp);
Mesh.publish("newTemp", buffer);
Mesh.off();
digitalWrite(D4, HIGH);
delay(1000);
digitalWrite(D4, LOW);
}
}