-
Does the code make the Puck's light flash?
It flashed!
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.
I will give this a try tomorrow. Thanks for the help!
-
Tried the example on the raspberry pi and got this output:
ubuntu@boontoo:~/motion-thermostat$ node test Noble: stateChange -> poweredOn Found device: 45:73:5f:0c:0d:10 Found device: 64:2b:d2:47:bd:00 Found device: cc:f4:11:98:5b:01 Found device: 05:c9:79:4c:61:39 Found device: 12:7d:20:2d:64:3b Found device: 0e:a1:1e:0e:0e:c2 Found device: 75:d9:c4:33:59:a8 Found device: 58:c6:8d:82:1f:a2 Found device: 06:42:db:89:b9:90 Found device: 2f:6a:ef:b1:6d:d2 Found device: 74:2f:a8:98:9c:57 Found device: 78:02:b7:23:6b:c2 Found device: 49:92:1d:5b:82:d6 Found device: 4b:ef:f5:a0:e9:2a Found device: 6b:73:24:90:68:e4 Found device: ea:c5:8b:e0:a4:fb Found device: 68:ce:65:cb:86:28 Found device: 0e:a1:1e:0e:0e:c2 Found device: 0c:80:5f:d6:bd:0c Found device: 0c:80:5f:d6:bd:0c Found device: 05:c9:79:4c:61:39 Found device: 90:dd:5d:e8:59:50 Found device: 54:e4:fc:4c:f1:9b Found device: 0e:a1:1e:0e:0e:c2 Found device: 45:73:5f:0c:0d:10 Found device: 64:2b:d2:47:bd:00 Found device: 3d:7f:60:53:b0:7d Found device: 55:2b:6a:2d:44:29 Found device: 5f:a3:6c:c7:29:84 Found device: 12:7d:20:2d:64:3b Found device: 75:d9:c4:33:59:a8 Found device: 58:c6:8d:82:1f:a2 Found device: 06:42:db:89:b9:90 Found device: 2f:6a:ef:b1:6d:d2 Found device: 74:2f:a8:98:9c:57 Found device: 0e:a1:1e:0e:0e:c2 Found device: 62:5e:f6:87:87:d9 Found device: 45:9a:95:02:55:00 Found device: 05:c9:79:4c:61:39 Found device: 90:dd:5d:e8:59:50 Found device: 54:e4:fc:4c:f1:9b Found device: 48:10:c1:2a:74:cc Found device: 48:10:c1:2a:74:cc Found device: f4:fe:fb:c4:58:4e Found device: 4e:b6:b3:37:6d:f9 Found device: 4e:b6:b3:37:6d:f9 Found device: 40:2d:01:84:21:eb Found device: 08:a1:94:e2:dd:f7 Found device: 0e:a1:1e:0e:0e:c2 Found device: 0c:80:5f:d6:bd:0c Found device: 69:be:d5:4e:3a:dc Found device: 6c:ef:9f:dd:1d:ae Found device: 64:2b:d2:47:bd:00 Found device: f4:fe:fb:c4:58:4e Found device: 55:2b:6a:2d:44:29 Found device: 67:8c:04:e3:bf:13 Found device: 67:8c:04:e3:bf:13 Found device: 90:dd:5d:e8:59:50 Found device: 7c:18:2f:c5:ce:04 Found device: 12:7d:20:2d:64:3b Found device: 5f:a3:6c:c7:29:84 Found device: 58:c6:8d:82:1f:a2 Found device: 5f:a3:6c:c7:29:84 Found device: 45:9a:95:02:55:00 Found device: 61:d5:e4:67:76:80 Found device: 61:d5:e4:67:76:80 Found device: 68:ce:65:cb:86:28 Found device: 08:a1:94:e2:dd:f7 Found device: 90:dd:5d:e8:59:50 Found device: f2:09:f2:78:7d:9a BT> Connecting Found device: f2:09:f2:78:7d:9a BT> Connecting BT> Connected BT> Connected Disconnected Disconnected Disconnected Disconnected ^Cubuntu@boontoo:~/motion-thermostat$
-
Here is the output I receive when I run the example code on my mac. It hangs at the second "connected":
± % node test.js !6614 Noble: stateChange -> poweredOn Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: be-89-30-00-21-95 Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: 90-dd-5d-e8-59-50 Found device: 90-dd-5d-e8-59-50 Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: Found device: f2-09-f2-78-7d-9a BT> Connecting Found device: f2-09-f2-78-7d-9a BT> Connecting BT> Connected BT> Connected ^C
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.
-
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.
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:
https://github.com/boomninjavanish/motion-thermostat
I will improve upon this project over time as I really needed the thermostat. (I plan on adding two more features to it soon.)