-
• #2
This is a web Bluetooth page yes? Double check you are not still connected to your computer via Bluetooth, say if you have uploaded code also via the Espruino IDE. That could account for the connect disconnect logs. Puck supports one connection on the BLE UART service
-
• #3
Hi Ollie, thanks for you answer. Yes, my note was connected to the puck. However, I still not figure out how to use the functions to handle the puck features.
I know that I have to use Puck.write and describe the function that I wanna use in the puck and than the callback. However, I cant for example call 'Puck.on('mag',function(xyv) {' using write. Can I? I saw in examples on internet connecting through IDE that the pages call the functions of puck directly. Like
var on = false; setInterval(function() { on = !on; LED1.write(on); }, 500);
How I can use javascript like that in my code? Can I?
Thanks Again
-
• #4
With complex procedures to call on Puck I find wrapping them as functions and saving them on puck first, is best. Then you call the function from inside
puck.write()
. You will probably need to callload()
to get them from flash first.Also check out
Bluetooth.println()
. I seem to think that is a better function for sending your return data over BLE UART.Edited:
Bluetooth.write()
to correctBluetooth.println()
-
• #5
I think there might be a bit of confusion because you can run code in two places - on the Puck itself or on the PC. Unfortunately both options allow you to use functions from the
Puck
object, which means it's not immediately obvious what you can do in each place.But on the PC, pretty much all you can do is
Puck.write
andPuck.eval
.Puck.write
is one-way - you're just sending to the Puck and not waiting for a responsePuck.eval
allows you to get a response back - in yourPuck.getBatteryPercentage()
you should really be usingeval
and notwrite
You can run
Puck.eval
in an interval, but I'd say that doing it every second is about the most you'd want.Take a look at the page on Web Bluetooth - it should explain most of this: https://www.espruino.com/Web+Bluetooth
Specifically if you want to send a bunch of information from the Puck (like magnetometer readings) then it'd be worth looking at the last section on two-way comms: https://www.espruino.com/Web+Bluetooth#two-way-communications
Instead of the light example there, using code that runs something like this on the Puck should work nicely for you:
Puck.magOn(); Puck.on('mag', function(xyz) { Bluetooth.println(xyz); });
edit: That still doesn't explain your disconnection issues though - is it possible that you actually just have a flat battery? That can often be a cause of stuff like this - there's enough charge for Puck.js to advertise, but when you connect it draws a bit more power, the voltage drops, and it resets.
-
• #6
Ah yes,
Bluetooth.println()
is what I was reaching for in my mind... On a mobile and a bit rusty :) Edited my post above to avoid any future misdirection. -
• #7
Mon 2019.06.10
re: 'I was having issues to connect with the espruino'
Hello @user100558, another item to consider, what version of Puck.js has been flashed?
Typeprocess.env
in L-Hand console side of the WebIDE. Please post results here.re: 'How I can use javascript like that in my code? Can I?'
Do these resources and examples aid in structuring your code?
http://www.espruino.com/Puck.js
http://www.espruino.com/Puck.js+SMS
http://www.espruino.com/Web+Bluetooth
Hi Guys,
I was having issues to connect with the espruino, but I was using the wrong code. So, I got how it works create my code, but now I'm receiving a return that my bluetooth is disconnected after connect. It is too weird. Do you know why?
Follow below my code and the response in chrome
Code:
Response: