Currently I'm trying to write a sketch that decodes the signal of the iTead intelligent switch, without not much luck. I have the documentation, but I don't know how to filter the OOK signal... http://blog.iteadstudio.com/itead-intelligent-switch-433mhz-communication-protocol/
Any idea?
(Of course, the sketch that iTead shared, not working...)
Thanks,
Here's the code you can use. I have a Mega, so for other boards slight modifications will be needed...
/*
Switch example for the iTead intelligent switch
Details about the protocol can be found here: http://blog.iteadstudio.com/itead-intelligent-switch-433mhz-communication-protocol/
DON'T FORGET, IF YOU WANT TO RECEIVE THE ID FROM THE SWITCH, CONNECT THE 433MHz RECEIVER TO INTERRUPT 2 THIS IS PIN21 ON THE ARDUINO MEGA
YOU CAN CHANGE THE INTERRUPT PIN IN THE SWITCH LIBRARY IN Switch.cpp
You can grab the library from here: http://blog.iteadstudio.com/itead-intelligent-switch-protocol-library-for-arduino/
Commands are in Hexadecimal, but the "switchit" using decimal codes.
Valid commands to send:
Control ON: 0×02 + 24-bit IDKEY
Control Off: 0×03 + 24-bit IDKEY
Control reverse status: 0×01 + 24 IDKEY
Request pairing command: 0×40000000 //not implemented in this code but easy to do if needed
ON status: 0×06 + 24-bit IDKEY
OFF status: 0×07 + 24-bit IDKEY
Successful pairing command: 0×50 + 24-bit IDKEY // Decimal: 80
YOU ARE FREE TO USE THE CODE WITH OR WITHOUT ANY MODIFICATION
Author: Zsolt Reinhardt
*/
#include <Switch.h> // using Itead's library for receiving packets
byte bytea;
byte byteb;
byte bytec;
byte mask = 1;
int sendbit[8];
int tx_pin=10; //PIN where the 433Mhz OOK transmitter connected
void setup() {
Switch.Init(115200);
pinMode(tx_pin,OUTPUT);
digitalWrite(tx_pin,LOW);
Serial.begin(115200);
Serial.println("Started...");
}
void loop() {
delay(10000); // Have some 10sec delay between status change
switchit(1,00,39,19); // This example sending a reverse status command to switch 003919 (decimal) ID.
// Code below is to receive the switch's ID for Arduino Mega connect the data pin of the 433MHz receiver module to PIN21
// In case you need to have the code of your switch, comment it out.
/* // Beginning of switch ID Reader code
while(1)
{
if(Switch.Available())
{
unsigned char value = Switch.Read();
Serial.print("Hex: ");
Serial.println(value,HEX);
Serial.print("Dec: ");
Serial.println(value,DEC);
Serial.println();
}
}
*/ // End of switch ID Reader code
}
void sendleadercode()
{
digitalWrite(tx_pin,HIGH);
delayMicroseconds(380);
digitalWrite(tx_pin,LOW);
delayMicroseconds(9920);
}
void sethigh()
{
digitalWrite(tx_pin,HIGH);
delayMicroseconds(380); //Can be adjusted to be more precise
digitalWrite(tx_pin,LOW);
delayMicroseconds(1090); //Can be adjusted to be more precise
}
void setlow()
{
digitalWrite(tx_pin,HIGH);
delayMicroseconds(380); //Can be adjusted to be more precise
digitalWrite(tx_pin,LOW);
delayMicroseconds(340); //Can be adjusted to be more precise
}
void switchit(int command, byte bytea, byte byteb, byte bytec){
Serial.print("Sending command: ");
Serial.println(command);
Serial.print("Sending to: ");
Serial.print(bytea,HEX);
Serial.print(" ");
Serial.print(byteb,HEX);
Serial.print(" ");
Serial.print(bytec,HEX);
Serial.print(" ");
Serial.println();
for(int i=0;i<8;i++){
sendleadercode();
sendbyte(command);
sendbyte(bytea);
sendbyte(byteb);
sendbyte(bytec);
}
}
void sendbyte(byte tosend){
int b=7;
for (mask = 00000001; mask>0; mask <<= 1) { //iterate through bit mask
if (tosend & mask){ // if bitwise AND resolves to true
sendbit[b]=1;
}
else{
sendbit[b]=0;
}
--b;
}
for(int i=0;i<8;i++){
if(sendbit[i]==0){
setlow();
} else {
sethigh();
}
}
}