xpress_embedo
Advanced Member level 4
- Joined
- Jul 5, 2011
- Messages
- 1,154
- Helped
- 161
- Reputation
- 396
- Reaction score
- 189
- Trophy points
- 1,353
- Location
- India
- Activity points
- 10,591
Hello!! Everyone!
Earlier i had sent data from PC, to Arduino using Ethernet, so i used a Arduino Mega and Ethernet Shield for this purpose, i connected Ardiuino Mega + Ethernet Shield directly with my PC and changed the IP address of my PC as per the server address set in the following sketch, and then used HW Hercules software to communicate with Arduino with PC over Ethernet.
But Now the case is little bit different, my Arduino+Ethernet Shield is connected with my PC directly, but there is a router in between it.
How can i receive the data from Arduino Mega on PC and Vice Versa with router in between, my setup is as follow:
Earlier i had sent data from PC, to Arduino using Ethernet, so i used a Arduino Mega and Ethernet Shield for this purpose, i connected Ardiuino Mega + Ethernet Shield directly with my PC and changed the IP address of my PC as per the server address set in the following sketch, and then used HW Hercules software to communicate with Arduino with PC over Ethernet.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 #include <SPI.h> #include <Ethernet.h> #define ETH_CS 10 #define SD_CS 4 // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield byte mac[] = {0xB0,0xCD,0xAE,0x0F,0xDE,0x10}; IPAddress ip(192,168,1,17); IPAddress server(192,168,1,10); EthernetClient client; void setup() { Serial.begin(9600); Serial.println("Starting Ethernet Connection"); pinMode(ETH_CS,OUTPUT); pinMode(SD_CS,OUTPUT); digitalWrite(ETH_CS,LOW); // Select the Ethernet Module. digitalWrite(SD_CS,HIGH); // De-Select the internal SD Card if (Ethernet.begin(mac) == 0) // Start in DHCP Mode { Serial.println("Failed to configure Ethernet using DHCP, using Static Mode"); // If DHCP Mode failed, start in Static Mode Ethernet.begin(mac, ip); } Serial.print("My IP address: "); for (byte thisByte = 0; thisByte < 4; thisByte++) { // print the value of each byte of the IP address: Serial.print(Ethernet.localIP()[thisByte], DEC); Serial.print("."); } Serial.println(); // give the Ethernet shield a second to initialize: delay(1000); Serial.println("connecting..."); // if you get a connection, report back via serial: if (client.connect(server, 5000)) { Serial.println("connected"); } else { // if you didn't get a connection to the server: Serial.println("connection failed"); } } void loop() { // if there are incoming bytes available // from the server, read them and print them: if (client.available()) { char c = client.read(); client.write(c); Serial.print(c); } // as long as there are bytes in the serial queue, // read them and send them out the socket if it's open: while (Serial.available() > 0) { char inChar = Serial.read(); if (client.connected()) { client.print(inChar); } } // if the server's disconnected, stop the client: if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop(); // do nothing: while(true); } }
But Now the case is little bit different, my Arduino+Ethernet Shield is connected with my PC directly, but there is a router in between it.
How can i receive the data from Arduino Mega on PC and Vice Versa with router in between, my setup is as follow: