

En realidad vamos a usar los comandos especificados por el fabricante, asi que técnicamente no es hacking, pero suficiente cerca 🙂
Requisitos
- Arduino MCU
- Modulo Serial HM10 BLE
- TSRB430 Relay Board
Arduino Code
[code]
#include <SoftwareSerial.h>
int bluetoothTx = 10; // TX-O pin of bluetooth
int bluetoothRx = 11; // RX-I pin of bluetooth
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup(){
Serial.begin(9600); // Begin the serial monitor at 9600bps
delay(200); // Short delay, wait for the Mate to send back CMD
bluetooth.begin(9600); // Start bluetooth serial at 9600
Serial.print(“send…”);
// bluetooth.print(“AT”);
//bluetooth.print(“e”); //open relay 1
//delay(2000);
//bluetooth.print(“o”); //close relay 1
}
void loop(){
if(bluetooth.available()){
Serial.print((char)bluetooth.read());
}
if(Serial.available()){
bluetooth.print((char)Serial.read());
}
}
void activateTSRB430() {
Serial.print(“commanding…”);
bluetooth.print(“110”);
delay(3000);
bluetooth.print(“100”);
delay(2000);
}
[/code]
Con este codigo conectamos un Arduino MCU con un modulo serial bluetooth y enviamos comandos una relay board TSRB430 HM-10 BLE.
Ahora hagamos lo mismo pero desde una RPi!
Requisitos
- RPi2
- Modulo Serial HM10 BLE
- TSRB430 Relay Board
Raspberry Pi2 Code
[code]</pre>
#!/usr/bin/env python
import serial
ser = serial.Serial(
port=’/dev/serial0′,
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
print “Serial is open: ” + str(ser.isOpen())
print “Now Writing”
ser.write(“e”)
#ser.write(“AT+CONNL”)
print “Did write, now read”
x = ser.readline()
print “got ‘” + x + “‘”
ser.close()
[/code]
Aqui enviamos el codigo e al relay board y podemos ver que el relay se cierra.
En el proximo tutorial veremos que podemos hacer con esta conexión.