IoT Arduino-Raspberry Pi Hackeando una TSRB430 BLE Relay Board P3

Raspberry Pi 2 Bluetooth Serial Uart HM10 HM12 Relay Board AI by Santiapps Marcio Valenzuela
Raspberry Pi 2 Bluetooth Serial Uart HM10 HM12 Relay Board AI


Continuamos haciendo la TSRB430 BLE pero ahora desde una Raspberry Pi 🙂



  1. RPi2
  2. Modulo Serial HM10 BLE
  3. TSRB430 Relay Board

Raspberry Pi2 Code

<pre>#!/usr/bin/env python

import serial

def convert_hex_to_int(hexChars):
    #convert string of hex chars to a list of ints
        ints = [ord(char) for char in hexChars]
        return ints
    except TypeError:
    return []
def convert_hex_to_bin_str(hexChars):
    #convert hex char into byte string
    response = convert_hex_to_int(hexChars)[0]
    # convert int to binary string
    responseBinary = bin(response)
    # first 2 chars of binary string are '0b' so ignore these
    return responseBinary[2:]

ser = serial.Serial(

print "Serial esta abierto: " + str(ser.isOpen())

print "Escribiendo..."
print "Escrito! Ahora leamos"
x = ser.readline()
print "got '" + x + "'"

responseBits = convert_hex_to_bin_str (x)
# binary conversion drops values until a 1 is encountered
# assume missing values are 0 and pad to give a value for all relays
responseBits = responseBits.zfill(4)
# reverse chars so that relay 1 is first
responseBits = list(responseBits)
# create dictionary of relay states
relayStates = {}
relay = 1
for bit in responseBits:
    relayStates[relay] = int(bit)
    relay += 1
print relayStates


Con esto ocupamos un poco mas de codigo para interpretar la respuesta del TSRB430.

Ahora podemos escribir y leer a los relays remotamente.

pi@raspberrypi:~/Documents/python $ python

Serial is open: True

Now Writing

Did write, now read

got ”

{1: 0, 2: 0, 3: 0, 4: 0}

pi@raspberrypi:~/Documents/python $

En el proximo tutorial veremos como usar estos códigos para crear un asistente personal que controla nuestra casa.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s