I am trying to use the resin.io API from a Raspberry device. The python code pushes some sample data to firebase properly. But once I want to push a resin environment variable I am unable to get the resin sdk for python. How should the library be referenced? The value I want to push is the UUID of the device connected to resin.io
#!/usr/bin/python
import time
import json
from resin import Resin
resin = Resin()
firebase_url = ‘https://temploggerpython.firebaseio.com/’ #Setup a loop to send Temperature values at fixed intervals in seconds
fixed_interval = 60 #Get the dive ID from Resin
deviceUUID = resin.models.device.identify()
while 1:
try:
temperature_c = “25.58” #current time and date
time_hhmmss = time.strftime(’%H:%M:%S’)
date_mmddyyyy = time.strftime(’%d/%m/%Y’)
First of all, if you are only interested in getting the device UUID, you might not need the SDK at all; your code can simply read the RESIN_DEVICE_UUID environment variable, which is set by default by the on-device Supervisor when it starts your application container.
Now, with regards to the particular NameError, have you tried logging in (e.g. see https://github.com/resin-io/resin-sdk-python#basic-usage) before invoking the resin.models.device.identify() method? @nghiant2710 might also have a few ideas here on the proper usage of the Python SDK if something is missing.
Hi Kostas,
Thanks for your answer. No, I did not tried to login as described on the link you have attached.
Can you give a hint how to read UUID env variable without the SDK? I am running the attached python code on a Raspberry Pi 3.
hey @Biagio74, there is an env var for the UUID: RESIN_DEVICE_UUID. We expose it in the container so you can just read from it.
Regarding the SDK, it’s weird since the issue indicates that resin variable is not defined. Can you please attached your python script here so I can try it?
Hi, thanks for the feedback.
Please see my python code at the link on DropBox. (I’m sorry I do not know how to attach nicely) https://towr.co/2pkZ51u
The functions get by name might not work for me. These devices later should be sent out to fields with the resin.io image and once they are online then they should start pushing data to some cloud (i.e Firebase)
My idea is to understand from that cloud service data that which devices they are coming from. Pls see an attached image from Firebase. So, instead of the location hard coded previously to the device (in this case Drammen-Norway) that should be the UUID. And based on that and thanks to the SDK other data could be fetched.
Regards, Balazs
But as we mentioned you don’t really need the sdk in this case because we expose the device uuid as an environment variable to your app so you could do…
deviceUUID = os.environ['RESIN_DEVICE_UUID']
... your code
Hi craig,
Thanks, now it works
Here it is what I did. Define the variable as suggested, but without from resin import Resin
Best Regards, Balazs
PS.: guys, thanks for the great support
Actually I removed it because of the error. And now, if I apply these codes then I have similar error. So, at the end it works without the import. Should it be mention resin in the requirements.txt? …I did not try now but before I did and did not help.
Here is the error in case import resin:
26.04.17 17:51:14 (+0200) Systemd init system enabled.
26.04.17 17:51:14 (+0200) systemd 215 running in system mode. (+PAM +AUDI
T +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPAR
MOR)
26.04.17 17:51:14 (+0200) Detected virtualization ‘other’.
26.04.17 17:51:14 (+0200) Detected architecture ‘arm’.
26.04.17 17:51:14 (+0200) Set hostname to <25f7e8e>.
26.04.17 17:51:18 (+0200) Traceback (most recent call last):
26.04.17 17:51:18 (+0200) File “data_logger.py”, line 5, in
26.04.17 17:51:18 (+0200) from resin import Resin
26.04.17 17:51:18 (+0200) ImportError: No module named resin