I’ve pretty much copy/pasted the code example into my code.I thought I had this working, but today I find my test device returning crap as the device name:
eg
I have pretty much the same issue, although the returned value differs a bit, and subsequent calls do usually return the correct device name. Hope someone comes up with a solution here though
Well this is interesting. Ive made a test version that does the Get Name every minute. The first request after a reset returns garbage, but subsequent requests return the correct name. So I guess the workaround is to do the request twice and ignore the first response.
Still seems strange that the first response is rubbish.
Exactly my issue as well. First request 50% of the time is faulty, but the second one 99% of the time is correct. Are you using a 3rd party simcard by any chance?
With my Particle simcard things worked fine, but I got one from Rogers (Canada; better deal on larger data volumes) and the issue only pertains to when I use Rogers sims.
It seems to be time dependent.
If I hit Get Name twice just after connecting to particle I get the same garbage twice. If I wait 20 seconds after connecting, everything is OK. 10 seconds is not enough. Didn’t bother hunting for the threshold timing.
So for some reason the event handler can be triggered before the firmware has a valid name from Particle, at which point it just serves up whatever crap happens to be in the buffer. This is looking like a firmware bug to me.
I should add I have threading enabled - maybe thats having unexpected consequences?
I think you are just seeing a race condition with the Cloud not starting up fully before you ask for the name. There are many similar case, such as the Cloud time setting. Can you try waiting for Time.isValid() to be true before asking?
I'm sure you are correct but I don't think that's going to work in my case because:
Used to check if current time is valid. This function will return true if:
Time has been set manually using Time.setTime()
Time has been successfully synchronized with the Particle Cloud. The device synchronizes time with the Particle Cloud during the handshake. The application may also manually synchronize time with Particle Cloud using Particle.syncTime() Correct time has been maintained by RTC. See information on Backup RAM (SRAM) for cases when RTC retains the time. RTC is part of the backup domain and retains its counters under the same conditions as Backup RAM.
To me, it looks like something is stepping on "device name" memory address. If you take it down to its bare minimum, you will at least eliminate the possibility that it is organic to your code snippets above (which it appears not to be).
something else is likely then to be corrupting this data...