Mesh functions which header

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

You can look in the open source repo

But you don’t need to include anything. If the functions aren’t found then that’s probably because you are not targeting a Mesh device :wink:

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

Edit: and @ScruffR beat me to it.

1 Like

Yes the Gold Star was not set for the Xenon so that done it builds which is great.

Thanks for that I was going quietly insane.

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

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,

There is no 0.7.0 for mesh devices. You are currently best served with 0.8.0-rc.27 for these devices.

This post might help you run the set target commands in workbench IDE:

That tutorial is outdated.
All Particle: Set * commands have been replaced with Particle: Configure Workspace for Device

Or you just manually add/edit the following entries in the .code-workspace file

    "settings": {
        "particle.targetDevice": "yourDeviceName", # optional 
        "particle.firmwareVersion": "0.8.0-rc.27",
        "particle.targetPlatform": "yourPlatform" # any of [ photon | p1 | electron | argon | boron | xenon ]
    },

2 Likes

Good stuff thanks again for all the help

1 Like

Awesome I now have it building and deploying to the Xenon is VSCode which is perfect.

Fantastic support here from the community you could not wish for more. (of course no doubt I will be asking more :slight_smile: )

2 Likes

And managed to do

particle serial list
particle serial monitor --port /dev/tty.usbmodem1431201

to see the debug output in VSCode so am now ready to actually cause some damage :rofl:

1 Like