├── Arduino_client_Static └── Arduino_client_Static.ino └── README.md /Arduino_client_Static/Arduino_client_Static.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | String message=""; 6 | byte mac[] = { 0x12, 0x8A, 0xAB, 0xAC, 0x2E, 0xA2 }; //giving the macID to the device 7 | 8 | //the IP address is dependent on your network 9 | // for manual configuration: 10 | IPAddress ip(192, 168, 1, 9);//ip address of the arduino 11 | //byte ip[] = { 192, 168, 1, 9 }; //giving IP to the bord//not required when DHCP is avalable 12 | 13 | // the subnet: 14 | //IPAddress subnet(255, 255, 255, 0); 15 | 16 | // the router's gateway address: 17 | //IPAddress gateway(192, 168, 1, 1); 18 | byte getway[] = {192, 168, 1, 100};////ip address of the port through which ardrino has connected 19 | 20 | 21 | 22 | // fill in your Domain Name Server address here: 23 | IPAddress myDns(8, 8, 8, 8); 24 | 25 | 26 | byte server[] = { 192, 168, 1, 100}; //specifying address of server 27 | //IPAddress server(192, 168, 1, 1); 28 | 29 | #define port 5001 //random port number to publish 30 | 31 | EthernetClient client; //making an object named client, of the class EthernetClient 32 | 33 | int connStatus(){ 34 | Ethernet.begin(mac, ip, myDns, getway); //If connection is not established then print the message 35 | 36 | //If connection is established then 37 | Serial.println(Ethernet.localIP()); 38 | return 1; 39 | } 40 | 41 | void setup() { 42 | Serial.begin(9600); 43 | while (!Serial) { 44 | ; // wait for serial port to connect. Needed for native USB port only 45 | } 46 | while(!connStatus()) 47 | connStatus(); 48 | } 49 | 50 | void loop() { 51 | 52 | if( client.connect(server,port)) 53 | { 54 | Serial.println("Connecting ......"); 55 | //if connection is established then do the following opoeration 56 | 57 | message += "IOT Client"; 58 | Serial.println(message); 59 | client.print(message); 60 | client.flush();//clearing the buffer 61 | client.stop();//closing the connection 62 | delay(1000);//giving some delay before throwing the next value 63 | message=""; 64 | } 65 | else 66 | { 67 | //If connection is not established then this part will be executed 68 | Serial.println("the socket connection is failed to connect to the specified port"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino-Client --------------------------------------------------------------------------------