Problem with jobs

Hi,
I have some difficulties in accessing to the args passed by a Job to my device.
For example, when in my job’s function I try to access to the value of the payload throught a key, there is always this error: [zlib_zdm.Device.handle_job_request TypeError @[0145:002F:0100:0034:00FF:0064:0090:0282]](javascript:window.except(’@[0145:002F:0100:0034:00FF:0064:0090:0282]’,'zlib_zdm.Device.handle_job_request TypeError ')).
How can I solve?
Thanks

Hi,

Please show us your code.

from zdm import zdm
from wireless import wifi

from espressif.esp32net import esp32wifi as wifi_driver
import streams
import json

device_id = ‘dev-4vsy8u3qirjj’
password = ‘eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkZXYtNHZzeTh1M3FpcmpqIiwidXNlciI6ImRldi00dnN5OHUzcWlyamoiLCJrZXkiOjIsImV4cCI6MjUxNjIzOTAyMn0.sHhALCOlBTZk8kHv6sHOD6Wz46W-dwfUkP7PjwPeCAk’

def custom_job_1(obj, arg):
print(“custom_job_1”)

return {
    'value 1': random(0, 100),
    'value 2': random(100, 200)
}

def custom_job_2(obj, arg):
print(“custom_job_2”)
print(arg)
if ‘value’ in arg:
print(arg[“value”])
return ‘this is an example result’

my_jobs = {
‘job1’: custom_job_1,
‘job2’: custom_job_2,
}

streams.serial()

try:
wifi_driver.auto_init()
for _ in range(5):
try:
print(“connect wifi”)

        wifi.link("Home&Life SuperWiFi-C9E5", wifi.WIFI_WPA2, "XR3UKA8RMRPTK7U3")
        print("connect wifi done")
        break
    except Exception as e:
        print("wifi connect err", e)


device = zdm.Device(device_id, jobs_dict=my_jobs)

device.set_password(password)
device.connect()

while True:
    sleep(1000)

except Exception as e:
print(“main”, e)

the code is the same of the example presented in zerynth. I want just read the args passed through the jobs in order to use these

Hi :slight_smile: can you please add a print in your code of the json message received by your device?
Probably there is an error accessing the field by the key.

Yes, but there are already two print in the second job’s function. The first one which prints the entire ‘arg’ dictionary, the second one which prints one of its field. I have a problem with this second print which returns the error I’ve written. I tried also to access the payload in this way: arg[‘args’][‘value’], but nothing

Can you please post here the entire message your device receive? If you’re sending the job using the GUI at zdm.zerynth.com probably there is an error in scheduling jobs with arguments, that will be fixed as soon as possible.

connect wifi

connect wifi done

zlib_zdm.Device.connect attempt

zlib_zdm.Device.subscribe attempt

zlib_zdm.Device.subscribe done

mqtt client connected succesfully

Replied to job: status

Replied to job: __manifest

Replied to job: __vm_info

zlib_zdm.Device.handle_delta_status received status delta

custom_job_1

Replied to job: job1

zlib_zdm.Device.handle_dn_msg received message

message: {“version”:1588436259856,“key”:"@job2",“value”:"{‘value’:23}"}

custom_job_2

{‘value’:23}

[zlib_zdm.Device.handle_job_request TypeError @[0145:001C:0100:0034:00FF:0064:0090:0282]](javascript:window.except(’@[0145:001C:0100:0034:00FF:0064:0090:0282]’,'zlib_zdm.Device.handle_job_request TypeError '))

I made some tests on your code. There is an error in the message creation from the ZDM GUI.
Thank you for reporting this issue, I will notify you here when the problem will be solved. :slight_smile: