Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include <EthernetUdp.h>
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- IPAddress arduinoIP(192, 168, 1, 120); /* Set this to the IP address you wish to give to the arduino */
- IPAddress wifiLinkIP(255,255,255,255);
- unsigned int lwrfUDPTxPort = 9760;
- EthernetUDP Udp;
- void setup()
- {
- Ethernet.begin(mac,arduinoIP);
- Udp.begin(lwrfUDPTxPort);
- Serial.begin(57600);
- }
- void loop()
- {
- if (Serial.available())
- {
- char c = Serial.read();
- if ((c == '0') || (c == '1'))
- {
- lw_udp_sendOnOff_text(6,0,c-'0', (char*)"Arduino set", &c);
- Serial.println("Switching Device State");
- }
- else if((c > '1') && (c <= '9'))
- {
- lw_udp_sendDIM(6 , 0, c-'0');
- }
- }
- }
- /* This is only necessary the first time the arduino is used. Once the
- arduino is registered with the wifi link, the mac/ip will be remembered*/
- void lw_udp_register()
- {
- char buffer [64];
- Udp.beginPacket(wifiLinkIP, lwrfUDPTxPort);
- (void)sprintf (buffer, "533, !R0D0F0|");
- Udp.write(buffer);
- Udp.endPacket();
- }
- /* This sends the On/Off message to the specified device */
- void lw_udp_sendOnOff(int room , int device, bool switchOn)
- {
- char buffer [64];
- Udp.beginPacket(wifiLinkIP, lwrfUDPTxPort);
- (void)sprintf (buffer, "000, !R%uD%uF%u|", room, device, switchOn);
- Udp.write(buffer);
- Udp.endPacket();
- }
- /* This sends the On/Off message to the specified device ,with two lines of text printed on the wifilink screen*/
- void lw_udp_sendOnOff_text(int room , int device, bool switchOn, char* line1, char* line2)
- {
- char buffer [64];
- Udp.beginPacket(wifiLinkIP, lwrfUDPTxPort);
- (void)sprintf (buffer, "000, !R%uD%uF%u|%s|%s", room, device, switchOn,line1, line2 );
- Udp.write(buffer);
- Udp.endPacket();
- }
- /* This sends the On/Off message to the specified device */
- void lw_udp_sendDIM(uint8_t room , uint8_t device, uint8_t dim)
- {
- if(dim <= 32)
- {
- char buffer [64];
- Udp.beginPacket(wifiLinkIP, lwrfUDPTxPort);
- Serial.println("Dimming light");
- (void)sprintf (buffer, "000, !R%uD%uFdP%u|", room, device, dim);
- Udp.write(buffer);
- Udp.endPacket();
- }
- else
- {
- Serial.println("Invalid dim value");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement