-
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()
-
-
Thanks Gordon,
i am using the following function on the puck, and ideally i would like to return something back to my python script. i.e temperature value.
function beam(ircode) { Puck.IR(require("pronto").decode(ircode)); return "test"; }
see below my python code as wel. i am so far getting the following value back from the puck, or is it not from the puck hhh
response value beam(sleep);
import sys from bluepy.btle import UUID, Peripheral import time import binascii command = "\x03\x10beam(" +sys.argv[2]+ ");\n" p = Peripheral(sys.argv[1], 'random') 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:]; time.sleep(1.0) # Allow sensor to stabilise [#uuidValue](https://forum.espruino.com/search/?q=%23uuidValue) = btle.UUID("f000aa71-0451-4000-b000-000000000000") [#lightSensorValue](https://forum.espruino.com/search/?q=%23lightSensorValue) = lightService.getCharacteristics(uuidValue)[0] val = ch.read() print "response value", val p.disconnect() finally: p.disconnect()
-
-
-
-
i noticed that when i try to run the code above, and then seperatly on another computer try to connect to the puck.js through the web console, that it no longer is found, only when i remove the battery, then i can find it on the web console. maybe the connection from the python code is not negociating properly
-
Amazing, saved me a heap of testing.
i get an error with your code
python puck_serial.py D8:19:E7:5B:3A:57
> Traceback (most recent call last): File "puck_serial.py", line 13, > in <module> > p = Peripheral(sys.argv[1], "random") File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 391, in > __init__ > self._connect(deviceAddr, addrType, iface) File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 439, in > _connect > raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp) > bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral > D8:19:E7:5B:3A:57, addr type: random
-
i am trying the following, but i get following error. any help please
Traceback (most recent call last): File "puck_serial.py", line 6, in
sock.connect((bd_addr,port)) File "<string>", line 5, in connect bluetooth.btcommon.BluetoothError: (112, 'Host is down')
from bluetooth import * import time bd_addr = "D8:19:E7:5B:3A:57" port = 1 sock = BluetoothSocket (RFCOMM) sock.connect((bd_addr,port)) print 'waiting' while 1: data = sock.recv(10) print data time.sleep(2.0) [#tosend](https://forum.espruino.com/search/?q=%23tosend) = raw_input() [#if](https://forum.espruino.com/search/?q=%23if) tosend != 'q': # sock.send(tosend) [#else](https://forum.espruino.com/search/?q=%23else): # break sock.close()
-
-
any recommendation for python. all i wish to do is to send a command i.e.
Puck.IR(require("pronto").decode("0000 006D 0000 0082 007D 003F 0010 0010 0010 0010 0010 002F 0010 0010 0010 002F 0010 0010 0010 0010 0010 0010 0010 002F 0010 002F 0010 0010 0010 0010 0010 0010 0010 002F 0010 002F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 002F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 002F 0010 0010 0010 0010 0010 0010 0010 0010 0010 002F 0010 002F 0010 002F 0010 002F 0010 002F 0010 002F 0010 002F 0010 002F 0010 0010 0010 0010 0010 002F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 002F 0010 002F 0010 0010 0010 0010 0010 002F 0010 0010 0010 0010 0010 0010 0010 002F 0010 0010 0010 002F 0010 0010 0010 002F 0010 0010 0010 0010 0010 0010 0010 002F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 002F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 002F 0010 0010 0010 0010 0010 0010 0010 002F 0010 0010 0010 002F 0010 0010 0010 0010 0010 002F 0010 0010 0010 003F"));
-
-
-
-
-
-
Hi,
I have tried using the IR on the Puck.js to operate a Fujitsu Air conditioner, it seems that the IR learning does not do anything to the Unit. so i tried searching for the Pronto Hex codes. i did find the following but again no luck.
http://files.remotecentral.com/ftp/irsheets/fujitsu-ac-arry16.zip
http://www.remotecentral.com/cgi-bin/mboard/rc-discrete/thread.cgi?4894,3here is the code i am using
var prontoHex = "0000 006D 0000 0082 007D 003F 0010 0011 0010 0011 0010 0030 0010 0011 0010 0030 0010 0011 0010 0011 0010 0011 0010 0030 0010 0030 0010 0011 0010 0011 0010 0011 0010 0030 0010 0030 0010 0010 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0030 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0030 0010 0011 0010 0011 0010 0011 0010 0011 0010 0030 0010 0030 0010 0030 0010 0030 0010 0030 0010 0030 0010 0030 0010 0030 0010 0011 0010 0011 0010 0030 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0030 0010 0030 0010 0011 0010 0011 0010 0030 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0030 0010 0030 0010 0011 0010 0010 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0011 0010 0030 0010 0030 0010 0030 0010 0011 0010 0011 0010 0011 0010 0030 0010 0030 0010 0011 0010 0011 0010 0011 0010 0011 0010 0030 0010 0F92"; var pulseTimes = require("pronto").decode(prontoHex); Puck.IR(pulseTimes);
Any help will be appreciated.
Thanks
-
-
the following seems to works. all good thanks
\x10Bluetooth.println(beam(mycool))\n