#include #include #include #include /*=============================================================================================================================== * Arduino BBSB Lan Repeater Code - Martyn Henderson (martgadget.blogspot.com) * * v0.1 - Repeats BUTTON->CONTROLLER->LAN->RADIO TX Only - My first attempt - pretty dumb booster for weak signal areas, does not at this point * repeat transmitter signals, it only re-transmits signals sent by the BBSB Controller. * * v0.2 - Repeats BUTTON->CONTROLLER->LAN->RADIO TX + - Events from Buttons heard by the BBSB controller and echoed on the network * LAN->RADIO TX - Packets sent to the BBSB controller by the local network OR Domia Online website * * v0.3 - As 0.2, but with minor fix. - Able to recieve device codes 10 and above (thanks Rob!) * These codes are untested as I dont have any BBSB devices that use them. * * * Credits: * * I think I wrote only 1/10 of this code total, the rest is the great work of these guys: * * UDP Support for Arduino Ethernet Sheild - bjoern@cs.stanford.edu 12/30/2008 * http://bitbucket.org/bjoern/arduino_osc/src/14667490521f/libraries/Ethernet/examples/UdpReceiveRaw/UdpReceiveRaw.pde * * RemoteSwitch library v1.2.1 made by Randy Simons http://randysimons.com * http://gathering.tweakers.net/forum/list_messages/1268154// * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * /*=============================================================================================================================== /* ETHERNET SHIELD CONFIGURATION * set MAC, IP address of Ethernet shield, its gateway, * and local port to listen on for incoming packets */ byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address to use (dont need to change unless you have several of these! byte ip[] = { 192, 168, 1, 12 }; // Arduino's IP address - change to a valid static IP on your lan. byte gw[] = { 192, 168, 1, 254 }; // Router/Gateway IP address - dont know why we need this. int localPort = 53007; // local port to listen on (no need to change) #define MAX_SIZE 45 // maximum packet size byte packetBuffer[MAX_SIZE]; //buffer to hold incoming packet int lastHouseCode; int lastDeviceCode; int lastStateCode; int intDisabled; int packetSize; // holds received packet size byte remoteIp[4]; // holds recvieved packet's originating IP unsigned int remotePort; // holds received packet's originating port int id; byte lastMessage[4]; //Intantiate a new KaKuSwitch remote - attach Radio transmitter to PIN 2. KaKuSwitch kaKuSwitch(2); int i; int ledPin = 13; // LED on PIN 13. /* SETUP: init Ethernet shield, start UDP listening, open serial port for debug */ void setup() { Ethernet.begin(mac,ip,gw); UdpRaw.begin(localPort); Serial.begin(38400); pinMode(ledPin, OUTPUT); // For LED if you have one on pin 13. intDisabled = 0; // enabled. 8-) } /* LOOP: wait for incoming packets and print each packet to the serial port */ void loop() { // if there's data available, read a packet if(UdpRaw.available()) { packetSize = UdpRaw.readPacket(packetBuffer,MAX_SIZE,remoteIp,(uint16_t *)&remotePort); // Serial.print("Received packet of size "); // Serial.println(abs(packetSize)); Serial.print("RX From IP "); for(i=0; i<3; i++) { Serial.print(remoteIp[i],DEC); Serial.print("."); } Serial.print(remoteIp[3],DEC); Serial.print(" Port "); Serial.print(remotePort); if(packetSize < 0) { // if return value <0 the packet was truncated to fit into our buffer Serial.print(" Packet truncated from "); Serial.print(packetSize*-1); Serial.print(" to "); Serial.print(MAX_SIZE); Serial.println(" bytes. (not a valid on/off signal)"); } Serial.print(" Contents:["); for(i=0; i