I finally got around to trying to start to code on the new Gen3 devices. I looked at the reference docs and thought great looks an easy addition.
Yet I find myself with the stupidest question known to man. Which header are the Mesh() functions in? I looked at other examples and see only Particle.h included. But using VSCode, with Particle.h in my .ino the IDE cannot resolve the Mesh functions so I went to the console, presuming my VSCode setup was borked, and clicked on the WebIDE and wrote the simplest code I could imagine and there too I get the same errors ‘Mesh is not defined in this scope’ errors. I start to trace through the .h fields from Particle to Application to the long inner list by hand… surely I have missed some thing simple and rather fundamental here.
What noob mistake am I making?
#include "Particle.h"
void setup() {
Mesh.connect();
waitUntil(Mesh.ready);
}
void loop() {
if (Mesh.Ready()) {
Serial.printlnf("Particle Mesh is Ready");
} else {
Serial.printlnf("Particle Mesh is NOT Ready");
}
}
Your code looks fine… as far as calling Mesh is concerned. Make sure you are targeting a mesh device. If using web IDE, click on the “devices” icon and click the star next to a mesh device. Not sure the equivalent command in workbench IDE. Hopefully, targeting a mesh device is all that you’re missing.
For some code cleanup… there’s no need to call Mesh.connect(); as that happens automatically. You may also want to add some sort of delay or millis timer to your loop because once Mesh.ready() returns, you will print uncontrollably to the serial monitor. Make sure you pay attention to the syntax… the commands are case sensitive so you’ll need a lowercase “r” for Mesh.ready().
#include "Particle.h"
unsigned long interval = 5000; //5 seconds * 1000 ms = 5000 ms
unsigned long lastMillis = 0;
void setup() {
waitUntil(Mesh.ready);
}
void loop() {
if (millis() - lastMillis > interval) {
if (Mesh.ready()) {
Serial.printlnf("Particle Mesh is Ready");
} else if (!Mesh.ready()) {
Serial.printlnf("Particle Mesh is NOT Ready");
}
lastMillis = millis();
}
}
Thanks for the rely. Yes your right with the timings I was only using that to compile and was not intending to flash without some safety nets but appreciated you pointed it out and even wrote the code to help
So my next 2 questions are:-
How do I achieve the same in VSCode as I use that for normal development and would prefer that to the WebIDE?
When I try do build in VSCode it is using DeviceOS 7.0 although I have ~/.particle/toolchains/deviceOS/0.8.0-rc.27/ in place. How go I get it to pickup different versions?
Thanks again for taking time out to answer the previous questions,