Two way communication using Python (bleak) / Cannot discover services & characteristics #3708
Replies: 7 comments
-
Posted at 2021-05-06 by @gfwilliams Hi! This sounds like a great project! With Bleak, did you try the code on https://www.espruino.com/Interfacing#bluetooth-le ? What error messages do you get? Actually trying to directly make HTTP requests from the Puck via some means is going to be difficult, but I feel like you've got a few different options:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-05-06 by boomNinjaVanish Here is the output I receive when I run the example code on my mac. It hangs at the second "connected":
EDIT: Changed the wording below to be less confusing. I am not making direct HTTP requests from the Puck but from a raspberry pi. How does one press a button on the device to trigger the HTTP request on the raspberry pi? Then after that poll the puck for the temperature? Sorry, I am new to BLE and have been confused by hours of reading about it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-05-06 by boomNinjaVanish Tried the example on the raspberry pi and got this output:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-05-06 by @gfwilliams So you're running the code from this example? https://www.espruino.com/Interfacing#node-js-javascript It seems that maybe it's trying to connect to the device twice, so you could try changing the code right at the top to:
Does the code make the Puck's light flash?
The best bet there is to use https://www.espruino.com/BLE+Advertising So on the Puck:
And then use the code from https://www.espruino.com/BLE+Advertising#node-js - either JS or Python. The first byte you get will be the button press count - so when it changes you can do your HTTP request - and the second byte is the temperature, so there's no need to request it - you just always have it available. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-05-06 by boomNinjaVanish
It flashed!
I will give this a try tomorrow. Thanks for the help! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-05-06 by @gfwilliams Great! Did you have to make the change I described above? If so I'll change the example code on the website |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-05-07 by boomNinjaVanish
Yup! That is what fixed it! I got the project to work the way I was expecting: the device may be flipped to turn the fan on and off and is controlled by a temperature. I used node with @abandonware/noble for the server like I wished! Now I know enough to make the project for my sister. I am super stoked! Thanks for the help! I now understand BLE two way communications! BTW -- if you want to post it as a project, I have the completed thermostat code and instructions here: I will improve upon this project over time as I really needed the thermostat. (I plan on adding two more features to it soon.) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2021-05-05 by boomNinjaVanish
tl;dr version: how do I push changes to a central device (Raspberry Pi)? Libraries I have tried do not discover UART service and characteristics.
Hi!
I am working on a project to help my disabled sister to operate devices in her house on her own. I am planning on using a combination of the Puck's accelerometer and a Raspberry Pi running this project: https://webgazer.cs.brown.edu/#examples. I hope to publish this as open source so that others may use the project for their needs as well. (Products in the medical industry are VERY expensive. I am hoping that making some things available for free would help those who cannot afford an expensive solution from Tobii/Dynavox.)
She cannot speak, walk, or move very well. However, she can make her Barbie dance by shaking it. I am hoping to harness that movement as an trigger for various home automation tasks in the future. My end-goal is to have her control everything in her environment. She would do this by gazing at the Raspberry Pi's screen to change which device/setting and shake the Puck to change the state of that device. She lives in an impoverished area without access to the internet, so I am looking to make a closed network of IoT devices for her.
Right now, I am starting small: I am making the Puck act as a thermostat and controller for a fan in my kitchen using http get requests to IFTTT.
After multiple hours of experimentation, I was able to get the Puck to receive commands from my macos device. However, I am having trouble figuring out how to have the server wait for a command from the the Puck. Is there a way to have the puck push data to the server? For example, if the puck has been flipped (accel.z < 0), I want to send an instruction to the server to shut off the fan. I also want to do this using as little power as possible.
One last thing: I was able to get the bleak library to work on both macos and Ubuntu on the Raspberry Pi. However, when I attempt to discover services and characteristics, the Puck doesn't respond. I have tried multiple libraries in both node js and python to no avail. (I would love to use @abandonware/noble in node but I could not get that to discover the UART characteristics as well. ) EDIT: To be clear: it does TX and RX to and from the server but discovery doesn't work.
Thanks for reading all of this. Here a link to the GitHub for the thermostat. I will make the eye gaze/motion project open source and available when I start it as well.
Beta Was this translation helpful? Give feedback.
All reactions