Read own API Key in UIFlow/micropython?
-
We have set up a number of M5 Stick Cs for remote IT education purposes. We have developed a cloud service for device management, and it is now possible to send a mac address (as a unique ID) from UIFlow to our cloud service using http. If we can upload the UIFlow API Key for each device at the same time as the macaddress, we think that we can distribute the m5f file to the managed M5 Stick C without having the students make notes.
Is there a way to access the device's API Key from Block or micropython?
-
Try
print(APIKEY) #or print(_APIKEY)
Should work. On device boot in serial monitor was displayed all boot messages includes apikey.
-
@robalstona Thanks for reply.
I tried the following code, but I get an error.
from m5stack import * from m5ui import * from uiflow import * setScreenColor(0x111111) print(APIKEY)
"_APIKEY" also resulted in an error.
Do I need to install any additional modules?
-
Try:
import deviceCfg print("APIKEY: " + deviceCfg.get_apikey())
But the APIKEY not fixed.I think you should use MAC addr for the devices:
import machine import binascii mac_addr = binascii.hexlify(machine.unique_id()).decode('utf-8')
-
@iamliubo, Thanks for reply!
By using this code, I was able to get the API Key:
import deviceCfg akey=deviceCfg.get_apikey()
BTW, the MAC address can be obtained with the following code:
macaddr=wifiCfg.wlan_sta.config('mac') macaddr='{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}'.format(*macaddr)
Thank you!
-
Hello, how about accessing the device's API key from Blockly? Is it possible? I am using M5 Stack new Stamp Pico.
-
@labixiaoxin8888 No need as the API key is stuck on the front of the stamp.
If you install Thonny and run the terminal monitor, the API's for any device connected will be shown in the terminal for Micropython.
-
@ajb2k3 Alright, thank you!
-
@ajb2k3 Is it possible to print any output for UI flow remote control website?
-
There is an experimental feature of Micropython called webRPEL
-
@ajb2k3 Thanks!