KMTronic DINo Internet Ethernet Relay IO board - UDP example

 
 

DINo Internet/Ethernet Relay I/O board

 

UDP control example



 

Download and unzip in your Arduino libraries folder "ENC28J60 EtherShield UDP Library"s

http://www.kmtronic.com/software/DINo/EtherShield_Arduino_v1.zip
 

 

 

Download and unzip "KMtronic_UDP_Example.pde"

http://www.kmtronic.com/software/DINo/UDP_Example/KMtronic_UDP_Example.zip

 

Connect board to USB, modify if necessary MAC and IP address and upload to board


Connect to your Router or PC Network Card and check for PING

 


 

UDP Commands:

 

FF 00 00 - Status Read command

FF 01 00 - Relay 1 OFF command
FF 01 01 - Relay 1 ON command
FF 02 00 - Relay 2 OFF command
FF 02 01 - Relay 2 ON command
FF 03 00 - Relay 3 OFF command
FF 03 01 - Relay 3 ON command
FF 04 00 - Relay 4 OFF command
FF 04 01 - Relay 4 ON command

 



UDP Test Software example including source code (C#)

KMTronic DINo 4 Relay UDP Test Software.zip
KMTronic DINo 4 Relay UDP Test Software Source Code.zip



Download, unzip and run software

 


Click on Open button and send FF0000 (Status request command)



If everything is okay you will receive IP DINo board and Status

 

 

UDP example code

--------------------------------------------------------------

           

  #include "EtherShield.h"

            uint8_t mymac[6] = {0xCF,0x70,0x7C,0xE4,0x8A,0xB8};
            uint8_t myip[4] = {192,168,1,25};
            uint16_t MYWWWPORT = 80;

            #define BUFFER_SIZE 750
            static uint8_t buf[BUFFER_SIZE+1];

            char reply[]="00000000";

            EtherShield es=EtherShield();

            uint16_t plen, dat_p;

            ///----------------------------------------------------------
            void setup(){

            Setup_Pins();
            es.ES_enc28j60Init(mymac);
            es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);

            } // end setup


            ///----------------------------------------------------------
            void loop(){

            // read packet, handle ping and wait for a tcp packet:
            dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));

            if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){
            Relay_Control();
            Status_Reply();
            es.ES_make_udp_reply_from_request(buf,reply,8,12345);
            buf[IP_PROTO_P]=0;
            }

            } // end loop


            ///----------------------------------------------------------
            void Setup_Pins(){

            pinMode(5, OUTPUT); digitalWrite(5, 0);
            pinMode(6, OUTPUT); digitalWrite(6, 0);
            pinMode(7, OUTPUT); digitalWrite(7, 0);
            pinMode(8, OUTPUT); digitalWrite(8, 0);

            } // end Setup_Pins


            ///----------------------------------------------------------
            void Relay_Control(){

              char* recv = (char*)buf + 42;

            if (strncmp(recv, "FF0100", 6) == 0) digitalWrite(8, 0);
            else if (strncmp(recv, "FF0101", 6) == 0) digitalWrite(8, 1);
            else if (strncmp(recv, "FF0200", 6) == 0) digitalWrite(7, 0);
            else if (strncmp(recv, "FF0201", 6) == 0) digitalWrite(7, 1);
            else if (strncmp(recv, "FF0300", 6) == 0) digitalWrite(6, 0);
            else if (strncmp(recv, "FF0301", 6) == 0) digitalWrite(6, 1);
            else if (strncmp(recv, "FF0400", 6) == 0) digitalWrite(5, 0);
            else if (strncmp(recv, "FF0401", 6) == 0) digitalWrite(5, 1);
            } // end Relay_Control


            ///----------------------------------------------------------
            void Status_Reply(){

              // Inputs
            reply[0] = digitalRead(A2) ? 0x31 : 0x30;
            reply[1] = digitalRead(A3) ? 0x31 : 0x30;
            reply[2] = digitalRead(A4) ? 0x31 : 0x30;
            reply[3] = digitalRead(A5) ? 0x31 : 0x30;

            // Outputs
            reply[4] = digitalRead(5) ? 0x31 : 0x30;
            reply[5] = digitalRead(6) ? 0x31 : 0x30;
            reply[6] = digitalRead(7) ? 0x31 : 0x30;
            reply[7] = digitalRead(8) ? 0x31 : 0x30;

            } // end Status_Reply
            ///----------------------------------------------------------


 
--------------------------------------------------------------

 

 

 

back to Arduino DINo projects

Read 8646 times