Transfering data from python code to Javascript docs and viceversa


#1

Hello everyone,
I’m working on a IoT project and I don’t know how to transfer data readed by my sensors to a Javascript function to use them in my web-designed app. I have read the Zerynth ADM documentation but I still can’t figure out how to do it. Anybody here have some examples or can explain me how to do it please?

Thank you for your support.


#2

Hi @Simone_Lungarella,

you can take a look at the Simple ADM example inside Zerynth Studio for sending data from a device to the ADM.
Then, to retrieve those data from your JS application, you can use the ADM API available through WebSockets.

Here the small JS library used by the ZerynthApp to communicate with the ADM.

Let me know :wink:


#3

Hi @LorenzoR,
I have read all the documentation about the ADM API but I didn’t find any helpful info because my target is to show the data received by a temperature sensor to the display. I have created the function on python, how explained in the ADM API, to get the value of our sensor but I don’t know how to receive the parameter and use it in a Javascript function.
Sorry if I can’t get it very quickly but this is my first IoT application with Zerynth, thanks for your interest and support, good evening.


#4

Hi @Simone_Lungarella,
In order to enable bidirectional communication between the template webpage and the device, the only necessary step is to include the ADM javascript library into the template and configure it with the appropriate callbacks.
Have a look at this link

Let me know if it’s still unclear.


#5

Hi @karimhamdy1, thanks for helping,
I’m using the callback "on_connected " but instead of showing a message like “CONNECTED” as in the example, I want to show 3 values sent by the functions defined in Python code:
zapp.event to link the values between JavaScript and Py;
zapp.on to link the function between JavaScript and Py;
(where zapp is ZerynthApp object).
My problem arises when I use the function Z.call in JS because I don’t know how to get the values sent.
Sorry if I ask it again but if you have some examples it would be great.


#6

Hi @Simone_Lungarella,

you can refer to this blog post for a complete example on how to send data from your device and catch them inside a JS application (from the ZerynthApp).

Let me know if I got your point this time :slight_smile:


#7

I have found the example that can help me here, thanks for the help guys, I can figure out how to do it now.