简体   繁体   中英

Particle.io read published variable from the device

I want to publish data using Particle.variable just so that on device reset, I can then read my latest state from the web again. Is it possible to read the data I had published from the device from the Cloud?

Short answer: It is probably possible!

Longer answer: Unfortunately, this doesn't seem to be supported directly by the Cloud Functions API ( https://docs.particle.io/reference/firmware/photon/#cloud-functions ). Most of these functions are geared towards sending data from the device, and the only one geared towards receiving data appears to be subscribe , which would require somebody else to publish while you are listening.

Of course, this device can make arbitrary HTTP(S) calls so you could use the TCPClient ( https://docs.particle.io/reference/firmware/photon/#tcpclient ) to make calls to get a variable value! ( https://docs.particle.io/reference/api/#get-a-variable-value )

This will require you to have an access token, however. So, you could: 1. Generate an access token out-of-band (manually on your computer) 2. Embed the access token in your code (WARNING do not publish code with your token embedded) 3. Make API calls to get the variable value

This might not work well if you want to release this product more broadly, and it might break down if the access token expires or is otherwise invalidated.

You may also want to look at using EEPROM for persistence if your data is very small ( https://docs.particle.io/reference/firmware/photon/#eeprom ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM