Closed MarkResting closed 9 months ago
What is not working for you? Without having tested, it looks about right to me.
I'm getting the error:
NameError: name 'cloud' is not defined
i think it's not difined in that registered function anymore,... so i don'tknow how to bring the data into a variable,...
sorry for these beginner questions.
Kind regards, Sebastian
Guess you haven't logged in to the cloud then or haven't initialized the object. Hard to say with that small code snip
Sorry, here's the full code:
import asyncio
import datetime
import json
import time
from os import environ
from pyworxcloud import WorxCloud
from pyworxcloud.events import LandroidEvent
from pyworxcloud.utils import DeviceHandler
tz = datetime.datetime.now().astimezone().tzinfo.tzname(None)
async def main():
loop = asyncio.get_running_loop()
await async_worx()
async def async_worx():
# Clear the screen for better visibility when debugging
# Initialize the class and connect
cloud = WorxCloud("mail", "Password", "worx")
cloud.authenticate()
cloud.connect()
cloud.set_callback(LandroidEvent.DATA_RECEIVED, receive_data)
## Force an data update
# device = cloud.devices[environ["DEV_NAME"]]
# cloud.update(device.serial_number)
print("Listening for new data")
while 1:
pass
#logTimestamp = str(datetime.now())
#logText = str(vars(cloud))
landroidLog = open('landroidLog.txt','a')
landroidLog.write(vars(cloud))
landroidLog.write(vars(cloud))
# Self explanatory - disconnect from the cloud
cloud.disconnect()
def receive_data(
name: str, device: DeviceHandler # pylint: disable=unused-argument
) -> None:
"""Callback function when the MQTT broker sends new data."""
print("Got data on MQTT from " + name)
#logTimestamp = str(datetime.now())
#logText = str(vars(cloud))
landroidLog = open('landroidLog.txt','a')
landroidLog.write(vars(cloud))
asyncio.run(main())
@MarkResting Please delete the email address and password from your comment and reset your password. Now it is possible for anyone to lock or control your Mower. And you haven't initialized the object cloud in the method receive_data. Probably you can use device.json_data, but i haven't test it...
d you haven't initialized the object cloud in the method receive_data. Probably you can use device.json_data, but i haven't test it...
OMG that was really stupid! THX for that remark. I will try youre hint.
Sorry to bother you again with this, but I'm still to stupid to get it done :-(
How does the "receive_data" function needs to look like? how can i reviere there to my "cloud" object.
i tried to define it global, but that doesn't help. or did i a mistake in the assignment:
"cloud.set_callback(LandroidEvent.DATA_RECEIVED, receive_data)"
Any help would be much appreciated
Did you look at https://github.com/MTrab/pyworxcloud/blob/master/test_async.py ??
Yes (copied from there) The only missing part is to print the received data there,...
That's plain normal Python
yeah,.... i an really beginner,...
Sorry,...
just need to know how to iterate through "device"
Hi, I try to use the youre testfile with the setCallback function and it prints the new status very well. But I'm not able to revere to the variables within the registered function.
Can you give me a tip how i can do that?
Here is the function part of whot I'm trying to do:
A big thx up front and kind regards, Mark