Connection to the device #1323
Replies: 6 comments
-
Posted at 2019-05-30 by Robin Thr 2019.05.30 Hi @user100558 There Isn't enough info there to assist you. Which device, (Puck?) what error, in response to what call? Please post your code, the error as seen in the left-hand console side of the IDE, and the results of The link to a tutorial, if one was used. Thank you |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-05-30 by @allObjects @user100558, could please show the request you sent to puck for checking the LED, the request you sent for the magnetometer? ...and publish the code you loaded on puck, if you loaded any. For the LED example, did you use this example from the Espruino site https://www.espruino.com/Web%20Bluetooth ? I guess that the code you sent to puck as string to do something with the magnetometer has some JS syntax issue. What you send to the puck you can verify in the IDE when typing it into the console. Get the Espruino IDE going in Chrome browser on your computer, connect to puck and type it in the left hand side pane - the console, and you get what you asked for. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-05-31 by user100558 Hi Guys, sorry for my mistake and didn't place the code. I'm using cordova with angular v 1.*. Follow: my head
Then, my code in the angular file.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-05-31 by @allObjects @user100558, now I see where your are coming from. I'll try to explain what is going on: In Think of puck's console like a command or terminal window of a computer. You can type something, and if the terminal / console program - understands it, it will respond. Similar you enter Puck's operating system - so to speak - though does not understand sh or bat shell commands, but it understands JavaScript. The data - or more precisely - source code you send to Puck as request is tried to be interpreted / executed and the response created in Puck's console is sent back to you. Where the confusion comes is that in your browser you have an object referred to with the global variable Let's have a look at the key method of the
and
I'm sure you have the Espruino Web IDE installed and you have connected to the Puck via BLE. Enter any of these strings in the console - left pane - and you see the same effect by directly entering into Puck's console. The console of Espruino Web IDE is nothing else than a terminal that sends your key strokes - command - to Puck, and displays what Puck responds: echoing your key strokes and on pressing enter printing the response of your entered command. Since there is no meaningful response to setting and resetting a LED and these methods on the LED objects return nothing - in this case
as response in the console - as the response to your command (beside the echo of what you typed).
The To be clear what the browser side
To see these details look at https://www.puck-js.com/puck.js - the function beginning with
To use the Replace
Since
Now you are able to get your Magnetometer example going in a similar way. Recap:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-05-31 by @allObjects The browser local 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.
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:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-05-31 by user100558 Thanks so much....I totally understand my mistakes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-05-30 by user100558
Hi,
I create and small app using angular to connect to the device. It was working to test the LED. However, when I send the command Puck.mag it is getting the error that the function doesnt exit.
Should I import any other library than puck.js?
I'm not understand why this error.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions