Is Mesh.ready() really ready?

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. :slight_smile:

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);

  }
}

Have you tried this with SYSTEM_THREAD(ENABLED); ?

Are you monitoring the current consumption and does this make a significant difference?

Hi @armor. I have not tried with SYSTEM_THREAD enabled. I will do that next. Also, yes, it looks like it is dropping from around 11ma to 8ma. I’ll report actual measurements first thing tomorrow morning.

Looks like it is averaging about 8.5mA when radios are off. Note this has the RGB LED breathing white and I have an MCP9808 temp sensor connected (however data sheet shows that it should nominally pull about 200-400 uA). When I fire up the radios and send data to the Argon I’m pulling about 18.7mA.

I did some testing on a Xenon with mesh.ready().
Mesh.ready() is not really ready :roll_eyes:
After mesh.ready I do a subscribe on a mesh topic.
I use an external antenna.
When I disconnect the external antenna and boot the device mesh.ready returns true, but the subscription did not work. The Xenon is rapidly flashing green so it’s still trying to connect to the mesh but the mesh.ready is returning true.
Maybe this is a bug?

1 Like

I’m seeing similar. With my Argon offline thus no mesh available my Xenon still reports Mesh.ready()==true

Mesh.ready() only indicates that the mesh network is connected. It’s possible for the mesh network to exist with the gateway offline. The mesh nodes can communicate with each other over UDP but cannot communicate with the Particle cloud. For that, you should check Particle.connected(), not Mesh.ready().

Ahh, ok. I had switched to Particle.connected(), so good to hear that’s the proper approach. Thanks