pi@raspberrypi:~ $ bash /home/pi/python/tempsensor.py
import-im6.q16: unable to open X server ' @ error/import.c/ImportImageCommand/358. import-im6.q16: unable to open X server ’ @ error/import.c/ImportImageCommand/358.
import-im6.q16: unable to open X server ' @ error/import.c/ImportImageCommand/358. import-im6.q16: unable to open X server ’ @ error/import.c/ImportImageCommand/358.
/home/pi/python/tempsensor.py: line 6: syntax error near unexpected token 30' /home/pi/python/tempsensor.py: line 6: time.sleep(30) #Sleep to allow wireless to connect before starting
I also created my own sensor in Cayene for my password and that sort of thing.
root@raspberrypi:~# sudo su
root@raspberrypi:~# cd /home/pi/python
root@raspberrypi:/home/pi/python# import tempsensor.py
import-im6.q16: unable to open X server `’ @ error/import.c/ImportImageCommand/358
Looks like you are not running the code correctly. Go up to the first post and read the Code section again. In the end you need to save the code to a file and then run it with python /path/to/file.py
Hello, I’m new to Python code and confused on the saving home/pi/python/ tempsensor.py. I’m I supposed to make the new folders in the Pi desktop or is there a way to do it with terminal commands?
Oops sorry, I missed typed that on the page here. Im trying to get the code from Ognqn.Chikov
for the DHT22 to work it reads out in the terminal but the device on the Dashboard says wait for live Data?
import cayenne.client as cayenne
import time
import Adafruit_DHT
time.sleep(60) #Sleep to allow wireless to connect before starting MQTT
MQTT_USERNAME = ""
MQTT_PASSWORD = ""
MQTT_CLIENT_ID = ""
client = cayenne.CayenneMQTTClient()
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
timestamp = 0
while True:
client.loop()
if (time.time() > timestamp + 5):
humidity11, temp11 = Adafruit_DHT.read_retry(11, 18) #11 is the sensor type, 18 is the GPIO pin number that DATA wire is connected to
humidity22, temp22 = Adafruit_DHT.read_retry(22, 19) #22 is the sensor type, 19 is the GPIO pin number that DATA wire is connected to
if temp11 is not None:
client.virtualWrite(1, temp11, cayenne.TYPE_TEMPERATURE, cayenne.UNIT_CELSIUS)
if humidity11 is not None:
client.virtualWrite(2, humidity11, cayenne.TYPE_RELATIVE_HUMIDITY, cayenne.UNIT_PERCENT)
if temp22 is not None:
client.virtualWrite(3, temp22, cayenne.TYPE_TEMPERATURE, cayenne.UNIT_CELSIUS)
if humidity22 is not None:
client.virtualWrite(4, humidity22, cayenne.TYPE_RELATIVE_HUMIDITY, cayenne.UNIT_PERCENT)
timestamp = time.time()
Ok, sorry for the confusion. I rebooted the Raspberry Pi 3 model B+ I’ve been trying this on the temp widget finally came up on the dashboard with the green plug sign in the corner and then later the humidity widget showed up.I wonder if I’m having some kind of internet problems. the IOS app works fine but the online dashboard is very slow with chrome and will not load with Internet Explorer. Internet speed test are good.
I renamed the previous Adafruit_Python_DHT to Adafruit_Python_DHT-old and ran the commands. I did see any errors come up. However I am still getting the same error.
Sorry for the confusion. the installation of the python lib was successful. I am still getting the same import error when trying to run it in Thonny IDE.
I ran python /home/pi/python/tempsensor.py in a command windows. I am getting “connected with result code 0”. So the same as 6f6326e7 got back Feb. but I’m only getting one line, where 6f6326e7 had multiple lines. This is also waiting for an hour.
git clone https://github.com/myDevicesIoT/Cayenne-MQTT-Python
cd Cayenne-MQTT-Python
python setup.py install
once done with installation navigate to example folder and open Example-03-CayenneClient.py using any editor.
Next, on your dashboard add a new device using Bring your own thing. copy the MQTT credential into the Example-03-CayenneClient.py file.
Save and exit.
Run this file sudo python Example-03-CayenneClient.py
your cayenne dashboard should be populated with three widgets. do till here and see if you can connect to cayenne succesfully, then let move on to DTH.