Connect to mdb42q from pi and control it ? #4054
Replies: 1 comment
-
Posted at 2022-06-22 by @fanoush
your code example is doing it the other way - from Espruino to the Pi, so which one you want and which device has GPIO connected to something? On Espruino side you can hook into incoming connection event and refuse any connection so you can filter by mac address even without secure connection if you wish.
Try also connection over BLE from the phone (e.g. via nrfConnect), does it work? What are you next steps if connection works? How do you plan to receive GPIO toggle command on Pi side (if this is the right direction)? Posted at 2022-06-22 by David1234321 maybe I didn't explain correct I have found this - and I can see it connect to the pi
what else do I need to write in order to make hi m"wait" for my command ON\Off? and do you have an exapmle what need to do on the pi side? Posted at 2022-06-22 by @fanoush connecting the opposite way does not help you in any way, you need example for the Pi which connects the other way, not this piece of JS code for MDBT42. Then you would just send piece of javascript to toggle GPIO. As a start you can use web page in Chromium on the PI as per https://www.espruino.com/Web+Bluetooth - this is the easiest thing and web bluetooth works on the Pi otherwise bluetooth in linux is a mess, there are many ways, maybe search raspberry forum or check this https://elinux.org/RPi_Bluetooth_LE#Using_Bluetooth_LE_with_Python or node.js via https://github.com/noble/noble or dierctly via https://www.npmjs.com/package/espruino which is using noble Posted at 2022-06-23 by David1234321 so maybe I'm not it the right place Thanks, Posted at 2022-06-23 by @fanoush
Espruino can be used on both sides quite easily. It is the linux on the Pi that is more complicated. Just found tutorial that may help a bit and describes various options , check https://www.espruino.com/BLE+Advertising Posted at 2022-06-23 by David1234321 I think we misunderstanding each other.... :-) can you show an example code to put on the mdb42q just to be connected and wait for message this is what I have done :
I can see the device in scanning
and on my PI I can see I'm connected now what I need to add in order to read the data I'm sending from the PI (sending json {'open'}) Thank you , Posted at 2022-06-23 by @fanoush
You don't need any code on mdb42q at all to do this. You also don't need to 'wait' on MDBT42 side for anything. You just need to connect from the pi to the MDBT42 and send JS code to set the GPIO as shown in example https://www.espruino.com/Web+Bluetooth that is the easiest way to do this. There are other ways with custom service on MDBT42 - see e.g. this https://www.espruino.com/BLE+Communications but this is more complicated. Since you are struggling even with the basics there is no point in doing that as step 1. As I see it, the biggest issue for you is how to write code on Pi side to connect and send string like As for refusing connection from unknown devices check https://www.espruino.com/BLE+Security but I wouldn't worry about that in step 1.
Yes, there seems to be a lot of misunderstanding on your side in both how BLE works and also what you exactly want to do and how :-) And BTW here is example of getting battery via (already suggested) espruino cli command Posted at 2022-06-23 by David1234321 I know the problem is on my side .... this is what I'm missing : I read somewhere I can use Node-RED for creating a project and connecting with the MDB42Q Posted at 2022-06-23 by @fanoush
no, https://www.espruino.com/Reference#Pin
output goes to bluetooth console but you probably don't read it at all
I think I linked more than enough guides already and it doesn't look like it helped Posted at 2022-06-29 by @gfwilliams I think @fanoush has provided loads of info already. But there is also https://www.espruino.com/Interfacing#bluetooth-le which provides you a bunch of examples to turn the LED on and off using Web Bluetooth, Node.js, Python, even the Bash shell - all of which should work on the Pi. For instance this single command when run in the shell on Raspberry Pi should do it once you use the Mac address of your MDBT42Q:
Worth noting that a few of the examples use |
Beta Was this translation helpful? Give feedback.
-
Posted at 2022-06-22 by David1234321
Hello,
I want to connect to the mdb42q from my pi and be able to send him 2 types of messages to light up 2 ciruict (let's make it simple - want to control 2 gpio "1""0" from the pi)
is there a guide \ example I can follow ?
also can I make a secure connection, meaning allow to connect only from known MAC address only?
so only my Pi will be able to connect to the device ?
Thanks,
I have try this example
My pi name is PI4 - I can see it in bluetooth and ble scan from my phone
so what is wrong? missing?
have try namePrefix: 'PI4'
have also try to use th service I used which is '1322' - get the same resualt
Beta Was this translation helpful? Give feedback.
All reactions