I have an ESP32 project Thing that connects to the Arduino Cloud and with one variable. makes swimming pool water temperature available to my Widget and subsequently to Alexa. I would also like to use Python on my PC and the ArduinoCloudClient to retrieve the value, write it to a ,reg file, and use it to update the Windows registry for a 3D Text screen saver value in my pool cabana PC.
I received some help on this project using a different method in a previous Topic from @J-M-L . He/She suggested using Python and IOT Cloud , so I decided to create a new, more succinct and detailed Topic.
So far, Thing created and works very well. Widgets work great. Alexa integration is great.
Pretty sure I can complete the .reg / .bat file process to update the registry and change the 3D Text.
I tried the "Cloud Python Doc" example in its entirety shown here and it worked perfectly https://docs.arduino.cc/arduino-cloud/guides/python/#install-packages
I then tried adapting my own situation to the above example. The following is my Thing Detail, Python Script and Shell output.
Problem is with the Python script using basic connection to my Device. It appears to run once and then I get an "exception: EOF ... violation of protocol" error. Not sure if it's a Python or Client issue.
Thing ID: dcac0c9f-5a79-436b-ae27-affd53d742a8
Variable Declaration: CloudTemperatureSensor pool_Temp Read Only Update: Periodically
Device ID: ee6dbf5b-cd98-4bf1-a9e2-59cf3cdc579a
My Python Script
import time
import logging
import sys
sys.path.append("lib")
from arduino_iot_cloud import ArduinoCloudClient
DEVICE_ID = b"ee6dxxxxxxxxxxxxxxxxxxxxxxdc579a"
SECRET_KEY = b"Eoxxxxxxxxxxxxxxxxxxxxx3n"
def logging_func():
logging.basicConfig(
datefmt="%H:%M:%S",
format="%(asctime)s.%(msecs)03d %(message)s",
level=logging.INFO,
)
# This function is executed each time the "pool_Temp" variable changes
def on_sensor_changed(client, value):
print("Pool Temperature is: ", value)
if __name__ == "__main__":
logging_func()
client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY)
client.register("pool_Temp", value=None, on_write=on_sensor_changed)
client.start()
Shell output:
12:01:03.475 task: pool_Temp created.
12:01:03.490 task: conn_task created.
12:01:03.490 Connecting to Arduino IoT cloud...
12:01:03.953 task: discovery created.
12:01:03.991 task: mqtt_task created.
12:01:03.991 Subscribe: b'/a/d/ee6dbf5b-cd98-4bf1-a9e2-59cf3cdc579a/e/i'.
12:01:04.226 task: conn_task complete.
12:01:05.220 Unkown record found: OTA_URL value:
12:01:05.220 Unkown record found: OTA_REQ value: False
12:01:05.360 Subscribe: b'/a/t/dcac0c9f-5a79-436b-ae27-affd53d742a8/e/i'.
12:01:05.438 Subscribe: b'/a/t/dcac0c9f-5a79-436b-ae27-affd53d742a8/shadow/i'.
12:01:05.735 Device configured via discovery protocol.
12:01:05.844 task: discovery complete.
12:01:05.906 Unkown record found: OTA_URL value:
12:01:05.906 Unkown record found: OTA_REQ value: False
Pool Temperature is: 78.48619079589844
12:01:58.032 task: mqtt_task raised exception: EOF occurred in violation of protocol (_ssl.c:2423).
12:01:58.093 task: conn_task created.
12:01:58.093 Connecting to Arduino IoT cloud...
12:01:58.514 Subscribe: b'/a/t/dcac0c9f-5a79-436b-ae27-affd53d742a8/e/i'.
12:01:58.593 task: mqtt_task created.
12:01:58.692 task: conn_task complete.
12:02:53.108 task: mqtt_task raised exception: EOF occurred in violation of protocol (_ssl.c:2423).
12:02:53.108 task: conn_task created.
12:02:53.108 Connecting to Arduino IoT cloud...
12:02:53.780 Subscribe: b'/a/t/dcac0c9f-5a79-436b-ae27-affd53d742a8/e/i'.
12:02:53.890 task: mqtt_task created.
12:02:53.983 task: conn_task complete.
Looks like it might be something simple, but ....
Thanks for any help.



