Most recent activity
-
thanks, so i have tried the following and it works but i do receive an echo of the input command. so i tried with the \x10, but this does not work, however i receive the following echoed back.
when issuing the following command
"beam(sleep)\n"
i get
{"topic":"/ble/data/d8:19:e7:5b:3a:57/nus/nus_rx","payload":"beam(sleep)\r\n","qos":0,"retain":false,"_msgid":"2846d788.245218"}
and
{"topic":"/ble/data/d8:19:e7:5b:3a:57/nus/nus_rx","payload":"=\"testing\"\r\n>","qos":0,"retain":false,"_msgid":"37141196.ec66fe"}
however when issuing the following command to rid of the echoed command
"\x10beam(sleep)\n"
i only get
{"topic":"/ble/data/d8:19:e7:5b:3a:57/nus/nus_rx","payload":"\"\x10beam(sleep)\n\"","qos":0,"retain":false,"_msgid":"7217a5c4.d44c8c"}
-
-
-
-
-
This my code so far on the puck , and I am able to connect using the python code below and send commands, but I am unable to return a value back, actually I do receive something, such as
<type 'str'> <- Serial1 >
but it should be temperature reading of the puck. any help please
Puck Code:
function beam(ircode) { Puck.IR(require("pronto").decode(ircode)); digitalWrite(LED2,1); setTimeout(function() { digitalWrite(LED2,0); }, delayInMilliseconds); return E.getTemperature(); }
Python:
import sys from bluepy.btle import UUID, Peripheral import time import binascii from bluepy import btle command = "\x03\x10beam(" +sys.argv[2]+ ");\n" class MyDelegate(btle.DefaultDelegate): def __init__(self): btle.DefaultDelegate.__init__(self) def handleNotification(self, cHandle, data): print("A notification was received: %s" %data) p = Peripheral(sys.argv[1], 'random') p.setDelegate(MyDelegate()) try: UartService=p.getServiceByUUID(UUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")) ch = UartService.getCharacteristics(UUID("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"))[0] while len(command)>0: ch.write(command[0:20]); command = command[20:]; p.writeCharacteristic(ch.valHandle+1, "\x02\x00") while True: if p.waitForNotifications(1.0): # handleNotification() was called continue print("Waiting...") # Perhaps do something else here [#rx](https://forum.espruino.com/search/?q=%23rx) = UartService.getCharacteristics(UUID("6E400003-B5A3-F393-E0A9-E50E24DCCA9E"))[0] [#val](https://forum.espruino.com/search/?q=%23val) = rx.read() [#print](https://forum.espruino.com/search/?q=%23print) val p.disconnect() finally: p.disconnect()
the following seems to works. all good thanks
\x10Bluetooth.println(beam(mycool))\n