-
The final working code was:
<html> <head> </head> <body> <script src="https://www.puck-js.com/puck.js"></script> <script> var d = new Date(); var n = Math.round(d.getTime()/1000); var puckCommand = String.fromCharCode(16)+"setTime(" + n + ")\n"; </script> <button onclick="Puck.write(puckCommand);">Set The Time</button> <button onclick="Puck.eval('new Date().toString()',function(x) { console.log(x); })">Get The Time</button> </body> </html>
I never got \x10 working in the code. As you said, there must be some HTML escaping going on somewhere.
-
-
-
Hmm. Typing that in the devtools console works for me too. I must be missing something very obvious.
Code is on: https://conorpuckjs.now.sh/web_bluetooth_set_time.html
-
-
-
I've hit that problem a few times. e.g. right now one of my Puck.write() calls is working but when I follow it with a Puck.eval(), it throws a JSON error which turns out to be due to trying to parse
Bluetooth.println(JSON.stringify(new Date().toString()))
Still trying to figure out what interaction of write() and eval() is causing that to appear as the response to eval(). Doing two eval() in a row is fine. And if I do write(), eval(), eval(), the second eval() is fine so write() is causing some issue.
<html> <head> </head> <body> <script src="https://www.puck-js.com/puck.js"></script> <script> var d = new Date(); var n = Math.round(d.getTime()/1000); var puckCommand = "setTime(" + n + ")\\n"; console.log(puckCommand); </script> <button onclick="Puck.write(puckCommand);">Set The Time</button> <button onclick="Puck.eval('new Date().toString()',function(x) { console.log(x); })">Get The Time</button> </body> </html>
-
-
-
I have Puck.write working fine but Puck.eval is throwing an error on Chrome on Ubuntu.
Same error no matter what command I try, even 1+1.
<button onclick="Puck.eval('1+1;',function(x) { console.log(x); })">Get The Time</button>
This is on 1v92.
Am I missing something obvious? Thanks!
Uncaught SyntaxError: Unexpected token U in JSON at position 0 at JSON.parse (<anonymous>) at puck.js:298 at Object.connection.cb (puck.js:235) at Object.ondata (puck.js:272) at Object.emit (puck.js:100) at BluetoothRemoteGATTCharacteristic.<anonymous> (puck.js:190)
-
-
-
I've having a weird issue on Puck with datetime.
I have "Send time to Espruino" set in the IDE.
If I do new Date(Date.now()).getHours() or new Date(Date.now()).getMinutes(), I get the right thing.
But new Date(Date.now()).getMonth() is returning 5 and new Date(Date.now()).getDay() is also returning 5. (That's for today). Yesterday it was 4 for getDay().
This is on 1v92 using standalone Windows IDE espruino_ide_win64_0v65.9
Any idea where this offset could be coming from?
-
-
Yup, that worked perfectly. Even with
Thanks!