The browser local Puck object is very helpful for essential and basic stuff, such as connectivity and sending data and receiving response back.
BUT: What if I want to execute something much more elaborate on my Puck and get the response back?
Response: create these elaborate code pieces in the Espruino IDE in the right hand side Editor pane as custom functions with your names and upload them to Puck (and save them there - so on re-power / restart, the functions are still there). Then just invoke these functions by the names in your local browser application.
For example, you create a function that responds in JSON battery percentage and BTN1 status - pressed or not.
function batAndBut() {
var responseObject = { battery: E.getBattery(), but: digitalRead(BTN1) };
var response = JSON.stringify(responseObject);
console.log(response);
}
The example is intentionally made verbose.
Upload this code to Puck. Then test it with entering
batAndBut();
in the console. The response you should see is something like:
{"battery":85,"but": 0}
Now, in your angular Web app you do something like that:
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
The browser local
Puck
object is very helpful for essential and basic stuff, such as connectivity and sending data and receiving response back.BUT: What if I want to execute something much more elaborate on my Puck and get the response back?
Response: create these elaborate code pieces in the Espruino IDE in the right hand side Editor pane as custom functions with your names and upload them to Puck (and save them there - so on re-power / restart, the functions are still there). Then just invoke these functions by the names in your local browser application.
For example, you create a function that responds in JSON battery percentage and BTN1 status - pressed or not.
The example is intentionally made verbose.
Upload this code to Puck. Then test it with entering
in the console. The response you should see is something like:
Now, in your angular Web app you do something like that:
Enjoy!
PS: since I could not test (yet), line 1 may need to be: