send command to Puck.JS from the raspberry without Espruino Hub install #2865
Replies: 32 comments
-
Posted at 2019-01-15 by Ollie I haven't used the hub stuff, but will that not work for you? To interact with a Puck you fundamentally only need a BLE library in the language you are most familiar with. With that you can connect to and use the pucks built in UART service. I think in Node the common one is Noble, but with any library you'd have to write code. I used a BLE library for Go sometime back and added an abstraction layer for Puck commands, including the ability to call functions. It works and might do what you need. Another option is of course, Web Bluetooth. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by Ossama any recommendation for python. all i wish to do is to send a command i.e.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by Ossama what would be the connection speed i need to set up |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by Ossama i am trying the following, but i get following error. any help please
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by @gfwilliams
You shouldn't need one at all - connection speed doesn't really apply for something like Bluetooth LE. You could look at using However if you're ok with JS then Noble for Node.js is probably one of the most stable BLE libraries out there. You could even use the code that the Espruino CLI tools use as a base: https://github.com/espruino/EspruinoTools/blob/gh-pages/core/serial_noble.js But at the end of the day you need to:
But if you just want an easy time of it, install EspruinoHub and then send an MQTT message containing your JS command to |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by @gfwilliams Looks like I posted my reply before I saw your last post. In your last post, you're using the You'll need to use |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by @gfwilliams Adafruit have a Python library for their Bluefruit stuff that may work for you: https://github.com/adafruit/Adafruit_Python_BluefruitLE/blob/master/examples/low_level.py But basically it looks like there's very little code out there for doing this on Python so you're making your life quite difficult. By contrast there's quite a lot of Node.js stuff. This example came up: https://github.com/tigoe/BluetoothLE-Examples/tree/master/noble/readSerial Or there's even this library https://www.npmjs.com/package/node-uartble |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by @gfwilliams Ok, I just created an example for you that should work:
In your case the text you want to write will be more than 20 characters, so you'll need to write it in 20 character chunks |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by @gfwilliams Ok, or code that actually does the splitting for you:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by Ossama Amazing, saved me a heap of testing. i get an error with your code
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by Ossama i noticed that when i try to run the code above, and then seperatly on another computer try to connect to the puck.js through the web console, that it no longer is found, only when i remove the battery, then i can find it on the web console. maybe the connection from the python code is not negociating properly |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by @gfwilliams That's odd - only difference I can see is when I used it, I typed in a lowercase address. Could you try that? In https://github.com/rlangoy/bluepy_examples_nRF51822_mbed/blob/master/writeLed2.py that I based it on there's a try...finally for disconnection but the exception that's reported is from earlier in the code, so that wouldn't have caused an issue. You could also try |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by Ossama the restarting of the bluetooth seems to release the connection, and hence able to find in the web console. but the lower case didn't fix the isse |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by Ollie Just a thought - maybe obvious to OP, maybe not. Rather than sending long commands and splitting, could wrap the control commands in functions and send to Puck from IDE and If anybody else uses Golang and Puck, this is the library I referred to. Tested on Mac and Raspberry Pi and I've had some joy with it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-16 by Ossama from debugging, the python script does not go past
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-17 by @gfwilliams Literally just change the python
Apart from the first 2 chars you're just sending JS, so if you want to send arguments it's as easy as |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-17 by Ossama Thanks Gordon, i am using the following function on the puck, and ideally i would like to return something back to my python script. i.e temperature value.
see below my python code as wel. i am so far getting the following value back from the puck, or is it not from the puck hhh
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-18 by @gfwilliams For receive you need the However, the best way to get data back from the Puck is to use notifications - but you'll have to find an example of how to do that with |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-19 by Ossama Thanks this is such an example, so i need to setup anything on the puck.js side? while True: is
sufficient |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-19 by Ossama This my code so far on the puck , and I am able to connect using the python code below and send commands, but I am unable to return a value back, actually I do receive something, such as
but it should be temperature reading of the puck. any help please Puck Code:
Python:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-21 by @gfwilliams Looks promising. I'd suggest changing
What's happening is, as mentioned in the code I posted,
If you removed the It's much easier to just stop Espruino writing stuff automatically with |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-21 by Ossama i really appreciate your help... Many thanks |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-21 by @gfwilliams You were so close! It's basically the same:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-21 by Ossama what about the result from the function, i.e i want to send ack back . also i am having issue publishing on the nodered from another lan machine |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-21 by Ossama maybe i should rephrase my last message, what is the best way to execute a function within the puck and get a response |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-21 by Ollie Any function with a return will give you a response to console. So will |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-21 by @gfwilliams Yes - instead of It's all basically just the same as I'd explained earlier when you were trying with Python |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-21 by Ossama thanks, so i have tried the following and it works but i do receive an echo of the input command. so i tried with the \x10, but this does not work, however i receive the following echoed back. when issuing the following command
i get
and
however when issuing the following command to rid of the echoed command
i only get
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-21 by Ossama the following seems to works. all good thanks \x10Bluetooth.println(beam(mycool))\n |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-02-14 by @gfwilliams In case anyone needs it, the Python code to transmit and receive is now at: http://www.espruino.com/Interfacing#python As is code in Node.js |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-15 by Ossama
How am i able to send a command from the Raspberry pi to the Puck.js without having to install the hub scripts.
i.e. connect over bluetooth to the puck.js send command and disconnect or some other nifty efficient way. i would like to send command from rpi to puck.js to send IR signal
Thanks
Beta Was this translation helpful? Give feedback.
All reactions