|
12 | 12 |
|
13 | 13 | This example includes the code from Example7_ConfigurePacketSwitchedData to let you see the SARA-R5's IP address.
|
14 | 14 | If you select "Ping":
|
15 |
| - The code asks for the IP Address of the SARA-R5 you want to communicate with |
| 15 | + The code asks for the IP Address of the "Pong" SARA-R5 |
16 | 16 | The code then opens a TCP socket to the "Pong" SARA-R5 using port number TCP_PORT
|
17 | 17 | The code sends an initial "Ping" using Write Socket Data (+USOWR)
|
18 | 18 | The code polls continuously. When a +UUSORD URC message is received, data is read and passed to the socketReadCallback.
|
19 | 19 | When "Pong" is received by the callback, the code sends "Ping" in reply
|
20 | 20 | The Ping-Pong repeats 100 times
|
21 |
| - The socket is closed after the 100th ping is sent |
| 21 | + The socket is closed after the 100th Ping is sent |
22 | 22 | If you select "Pong":
|
23 |
| - The code opens a TCP socket and waits for data to arrive |
| 23 | + The code opens a TCP socket and waits for a connection and for data to arrive |
24 | 24 | The code polls continuously. When a +UUSORD URC message is received, data is read and passed to the socketReadCallback.
|
25 | 25 | When "Ping" is received by the callback, the code sends "Pong" in reply
|
26 |
| - The socket is closed after 600 seconds |
| 26 | + The socket is closed after 120 seconds |
27 | 27 | Start the "Pong" first!
|
28 | 28 |
|
| 29 | + You may find that your service provider is blocking incoming TCP connections to the SARA-R5, preventing the "Pong" from working... |
| 30 | + If that is the case, you can use this code to play ping-pong with another computer acting as a TCP Echo Server. |
| 31 | + Here's a quick how-to (assuming you are familiar with Python): |
| 32 | + Open up a Python editor on your computer |
| 33 | + Grab yourself some simple TCP Echo Server code: |
| 34 | + The third example here works well: https://rosettacode.org/wiki/Echo_server#Python |
| 35 | + Log in to your router |
| 36 | + Find your local IP address (usually 192.168.0.something) |
| 37 | + Go into your router's Security / Port Forwarding settings: |
| 38 | + Create a new port forwarding rule |
| 39 | + The IP address is your local IP address |
| 40 | + Set the local port range to 1200-1200 (if you changed TCP_PORT, use that port number instead) |
| 41 | + Set the external port range to 1200-1200 |
| 42 | + Set the protocol to TCP |
| 43 | + Enable the rule |
| 44 | + This will open up a direct connection from the outside world, through your router, to port 1200 on your computer |
| 45 | + Remember to lock it down again when you're done! |
| 46 | + Edit the Python code and replace 'localhost' with your local IP number: |
| 47 | + HOST = '192.168.0.nnn' |
| 48 | + Change the PORT to 1200: |
| 49 | + PORT = 1200 |
| 50 | + Run the Python code |
| 51 | + Ask Google for your computer's public IP address: |
| 52 | + Google "what is my IP address" |
| 53 | + Run this code and choose the "Ping" option |
| 54 | + Enter your computer's public IP address when asked |
| 55 | + Sit back and watch the ping-pong! |
| 56 | + The code will stop after 100 Pings+Echos and 100 Pongs+Echos |
| 57 | + That's 400 TCP transfers in total! |
| 58 | +
|
29 | 59 | Feel like supporting open source hardware?
|
30 | 60 | Buy a board from SparkFun!
|
31 | 61 |
|
@@ -68,7 +98,7 @@ const int pingPongLimit = 100;
|
68 | 98 |
|
69 | 99 | // Keep track of how long the socket has been open. "Pong" closes the socket when timeLimit (millis) is reached.
|
70 | 100 | unsigned long startTime;
|
71 |
| -const unsigned long timeLimit = 600000; // 600 seconds |
| 101 | +const unsigned long timeLimit = 120000; // 120 seconds |
72 | 102 |
|
73 | 103 | #include <IPAddress.h> // Needed for sockets
|
74 | 104 | volatile int socketNum;
|
@@ -189,7 +219,7 @@ void setup()
|
189 | 219 | while (Serial.available()) // Empty the serial RX buffer
|
190 | 220 | Serial.read();
|
191 | 221 |
|
192 |
| - mySARA.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial |
| 222 | + //mySARA.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial |
193 | 223 |
|
194 | 224 | // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
|
195 | 225 | // Comment the next line if required
|
@@ -397,11 +427,7 @@ void setup()
|
397 | 427 | if (c == '\n') // Is it a LF?
|
398 | 428 | {
|
399 | 429 | theAddress[field] = val; // Store the current value
|
400 |
| - if ((field == 3) |
401 |
| - && (theAddress[0] >= 0) && (theAddress[0] <= 255) |
402 |
| - && (theAddress[1] >= 0) && (theAddress[1] <= 255) |
403 |
| - && (theAddress[2] >= 0) && (theAddress[2] <= 255) |
404 |
| - && (theAddress[3] >= 0) && (theAddress[3] <= 255)) |
| 430 | + if (field == 3) |
405 | 431 | selected = true;
|
406 | 432 | else
|
407 | 433 | {
|
|
0 commit comments