Skip to content

Instantly share code, notes, and snippets.

@lazyatom
Created Mar 7, 2012
Embed
What would you like to do?
Arduino Ethernet flaky transfer example
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD }; //physical mac address
EthernetClient client;
#define debug(a) Serial.print(millis()); Serial.print(": "); Serial.println(a);
#define debug2(a, b) Serial.print(millis()); Serial.print(": "); Serial.print(a); Serial.println(b);
void setup(){
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
debug("DHCP Failed");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// print your local IP address:
debug2("IP address: ", Ethernet.localIP());
}
char* host = "192.168.1.22";
int port = 4567;
char *path = "/";
int totalRequestSize = 8346;
int failures = 0;
int requests = 0;
void loop() {
if (client.connect(host, port)) {
debug("Connected.");
client.print("GET "); client.print(path); client.println(" HTTP/1.0\n");
int length = 0;
while(client.connected() && !client.available()) delay(1); //waits for data
while(client.available()) {
client.read();
length++;
}
client.stop();
requests++;
if (length != totalRequestSize) {
failures++;
}
debug2("Total read: ", length);
Serial.print("Total failures: "); Serial.print(failures); Serial.print("/"); Serial.println(requests);
} else {
debug("Couldn't connect.");
}
}
require "rubygems"
require "sinatra"
get "/" do
(("#" * 80) + "\n") * 100
end
4501: IP address: 192.168.1.17
4504: Connected.
6285: Total read: 8346
Total failures: 0/1
6288: Connected.
8069: Total read: 8346
Total failures: 0/2
8273: Connected.
10053: Total read: 8346
Total failures: 0/3
10056: Connected.
11837: Total read: 8346
Total failures: 0/4
12042: Connected.
14024: Total read: 8346
Total failures: 0/5
14027: Connected.
15808: Total read: 8346
Total failures: 0/6
15811: Connected.
17794: Total read: 8346
Total failures: 0/7
17797: Connected.
19577: Total read: 8346
Total failures: 0/8
19580: Connected.
21362: Total read: 8346
Total failures: 0/9
21365: Connected.
23146: Total read: 8346
Total failures: 0/10
23149: Connected.
24930: Total read: 8346
Total failures: 0/11
24933: Connected.
26715: Total read: 8346
Total failures: 0/12
26718: Connected.
28498: Total read: 8346
Total failures: 0/13
28502: Connected.
30283: Total read: 8346
Total failures: 0/14
30286: Connected.
32067: Total read: 8346
Total failures: 0/15
32070: Connected.
33851: Total read: 8346
Total failures: 0/16
33854: Connected.
35636: Total read: 8346
Total failures: 0/17
35639: Connected.
37420: Total read: 8346
Total failures: 0/18
37423: Connected.
39204: Total read: 8346
Total failures: 0/19
39207: Connected.
40988: Total read: 8346
Total failures: 0/20
40991: Connected.
42772: Total read: 8346
Total failures: 0/21
42775: Connected.
44557: Total read: 8346
Total failures: 0/22
44560: Connected.
46341: Total read: 8346
Total failures: 0/23
46344: Connected.
48125: Total read: 8346
Total failures: 0/24
48129: Connected.
49910: Total read: 8346
Total failures: 0/25
49913: Connected.
51697: Total read: 8346
Total failures: 0/26
51700: Connected.
53482: Total read: 8346
Total failures: 0/27
53485: Connected.
55267: Total read: 8346
Total failures: 0/28
55270: Connected.
57052: Total read: 8346
Total failures: 0/29
57055: Connected.
58835: Total read: 8346
Total failures: 0/30
58839: Connected.
60619: Total read: 8346
Total failures: 0/31
60622: Connected.
62404: Total read: 8346
Total failures: 0/32
62407: Connected.
64188: Total read: 8346
Total failures: 0/33
64191: Connected.
65973: Total read: 8346
Total failures: 0/34
65976: Connected.
67757: Total read: 8346
Total failures: 0/35
67760: Connected.
69541: Total read: 8346
Total failures: 0/36
69544: Connected.
71325: Total read: 8346
Total failures: 0/37
71328: Connected.
73109: Total read: 8346
Total failures: 0/38
73112: Connected.
74894: Total read: 8346
Total failures: 0/39
74897: Connected.
76678: Total read: 8346
Total failures: 0/40
76681: Connected.
78462: Total read: 8346
Total failures: 0/41
78466: Connected.
80510: Total read: 4890
Total failures: 1/42
80514: Connected.
82294: Total read: 8346
Total failures: 1/43
82297: Connected.
84079: Total read: 8346
Total failures: 1/44
84082: Connected.
85863: Total read: 8346
Total failures: 1/45
85866: Connected.
87647: Total read: 8346
Total failures: 1/46
87650: Connected.
89432: Total read: 8346
Total failures: 1/47
89435: Connected.
91215: Total read: 8346
Total failures: 1/48
91218: Connected.
92999: Total read: 8346
Total failures: 1/49
93002: Connected.
94784: Total read: 8346
Total failures: 1/50
94787: Connected.
96568: Total read: 8346
Total failures: 1/51
96571: Connected.
98553: Total read: 8346
Total failures: 1/52
98556: Connected.
100338: Total read: 8346
Total failures: 1/53
100341: Connected.
102122: Total read: 8346
Total failures: 1/54
102125: Connected.
103907: Total read: 8346
Total failures: 1/55
103910: Connected.
105691: Total read: 8346
Total failures: 1/56
105695: Connected.
107475: Total read: 8346
Total failures: 1/57
107479: Connected.
109119: Total read: 2989
Total failures: 2/58
109122: Connected.
111167: Total read: 4889
Total failures: 3/59
111170: Connected.
112951: Total read: 8346
Total failures: 3/60
112954: Connected.
114736: Total read: 8346
Total failures: 3/61
114739: Connected.
116519: Total read: 8346
Total failures: 3/62
116523: Connected.
118304: Total read: 8346
Total failures: 3/63
118307: Connected.
120088: Total read: 8346
Total failures: 3/64
120293: Connected.
122074: Total read: 8346
Total failures: 3/65
122077: Connected.
123858: Total read: 8346
Total failures: 3/66
123862: Connected.
125642: Total read: 8346
Total failures: 3/67
125645: Connected.
127427: Total read: 8346
Total failures: 3/68
127430: Connected.
129212: Total read: 8346
Total failures: 3/69
129215: Connected.
130996: Total read: 8346
Total failures: 3/70
130999: Connected.
132781: Total read: 8346
Total failures: 3/71
132784: Connected.
134565: Total read: 8346
Total failures: 3/72
134568: Connected.
136349: Total read: 8346
Total failures: 3/73
136352: Connected.
138134: Total read: 8346
Total failures: 3/74
138137: Connected.
140182: Total read: 4889
Total failures: 4/75
140185: Connected.
142230: Total read: 4889
Total failures: 5/76
142233: Connected.
144014: Total read: 8346
Total failures: 5/77
144017: Connected.
145799: Total read: 8346
Total failures: 5/78
145802: Connected.
147582: Total read: 8346
Total failures: 5/79
147586: Connected.
148953: Total read: 1706
Total failures: 6/80
148956: Connected.
150736: Total read: 8346
Total failures: 6/81
150739: Connected.
152520: Total read: 8346
Total failures: 6/82
152524: Connected.
154305: Total read: 8346
Total failures: 6/83
154308: Connected.
156090: Total read: 8346
Total failures: 6/84
156093: Connected.
157874: Total read: 8346
Total failures: 6/85
157877: Connected.
159659: Total read: 8346
Total failures: 6/86
159662: Connected.
161442: Total read: 8346
Total failures: 6/87
161445: Connected.
163227: Total read: 8346
Total failures: 6/88
163230: Connected.
165012: Total read: 8346
Total failures: 6/89
165015: Connected.
166796: Total read: 8346
Total failures: 6/90
166799: Connected.
168781: Total read: 8346
Total failures: 6/91
168784: Connected.
170566: Total read: 8346
Total failures: 6/92
170569: Connected.
172350: Total read: 8346
Total failures: 6/93
172555: Connected.
174336: Total read: 8346
Total failures: 6/94
174339: Connected.
175706: Total read: 1706
Total failures: 7/95
175709: Connected.
177753: Total read: 4889
Total failures: 8/96
177756: Connected.
179536: Total read: 8346
Total failures: 8/97
179539: Connected.
181321: Total read: 8346
Total failures: 8/98
181324: Connected.
182976: Total read: 7740
Total failures: 9/99
182979: Connected.
184761: Total read: 8346
Total failures: 9/100
184764: Connected.
186546: Total read: 8346
Total failures: 9/101
186549: Connected.
188190: Total read: 2989
Total failures: 10/102
188193: Connected.
189976: Total read: 8346
Total failures: 10/103
189979: Connected.
191762: Total read: 8346
Total failures: 10/104
191765: Connected.
194013: Total read: 4894
Total failures: 11/105
194016: Connected.
195799: Total read: 8346
Total failures: 11/106
195802: Connected.
197584: Total read: 8346
Total failures: 11/107
197587: Connected.
199370: Total read: 8346
Total failures: 11/108
199373: Connected.
201156: Total read: 8346
Total failures: 11/109
201159: Connected.
202942: Total read: 8346
Total failures: 11/110
202945: Connected.
204728: Total read: 8346
Total failures: 11/111
204732: Connected.
206514: Total read: 8346
Total failures: 11/112
206517: Connected.
208301: Total read: 8346
Total failures: 11/113
208304: Connected.
210086: Total read: 8346
Total failures: 11/114
210089: Connected.
211872: Total read: 8346
Total failures: 11/115
211875: Connected.
213658: Total read: 8346
Total failures: 11/116
213661: Connected.
215444: Total read: 8346
Total failures: 11/117
215448: Connected.
217230: Total read: 8346
Total failures: 11/118
217234: Connected.
219016: Total read: 8346
Total failures: 11/119
219020: Connected.
220802: Total read: 8346
Total failures: 11/120
220806: Connected.
222447: Total read: 2989
Total failures: 12/121
222450: Connected.
224233: Total read: 8346
Total failures: 12/122
224236: Connected.
226019: Total read: 8346
Total failures: 12/123
226022: Connected.
227805: Total read: 8346
Total failures: 12/124
227808: Connected.
229591: Total read: 8346
Total failures: 12/125
229594: Connected.
231640: Total read: 4890
Total failures: 13/126
231643: Connected.
233425: Total read: 8346
Total failures: 13/127
233428: Connected.
235412: Total read: 8346
Total failures: 13/128
235415: Connected.
237399: Total read: 8346
Total failures: 13/129
237403: Connected.
239185: Total read: 8346
Total failures: 13/130
239188: Connected.
240971: Total read: 8346
Total failures: 13/131
240974: Connected.
242757: Total read: 8346
Total failures: 13/132
242760: Connected.
245009: Total read: 4895
Total failures: 14/133
245012: Connected.
246795: Total read: 8346
Total failures: 14/134
246798: Connected.
248581: Total read: 8346
Total failures: 14/135
248584: Connected.
250366: Total read: 8346
Total failures: 14/136
250370: Connected.
252152: Total read: 8346
Total failures: 14/137
252156: Connected.
253939: Total read: 8346
Total failures: 14/138
253942: Connected.
255725: Total read: 8346
Total failures: 14/139
255728: Connected.
257511: Total read: 8346
Total failures: 14/140
257514: Connected.
259297: Total read: 8346
Total failures: 14/141
259300: Connected.
261083: Total read: 8346
Total failures: 14/142
261086: Connected.
262868: Total read: 8346
Total failures: 14/143
262873: Connected.
264655: Total read: 8346
Total failures: 14/144
264658: Connected.
266441: Total read: 8346
Total failures: 14/145
266444: Connected.
268227: Total read: 8346
Total failures: 14/146
268230: Connected.
270215: Total read: 8346
Total failures: 14/147
270218: Connected.
272001: Total read: 8346
Total failures: 14/148
272004: Connected.
273786: Total read: 8346
Total failures: 14/149
273789: Connected.
275572: Total read: 8346
Total failures: 14/150
275575: Connected.
277358: Total read: 8346
Total failures: 14/151
277362: Connected.
279144: Total read: 8346
Total failures: 14/152
279147: Connected.
280930: Total read: 8346
Total failures: 14/153
280933: Connected.
282716: Total read: 8346
Total failures: 14/154
282720: Connected.
284503: Total read: 8346
Total failures: 14/155
284506: Connected.
286934: Total read: 8346
Total failures: 14/156
286938: Connected.
288922: Total read: 8346
Total failures: 14/157
288925: Connected.
290708: Total read: 8346
Total failures: 14/158
290711: Connected.
292696: Total read: 8346
Total failures: 14/159
292699: Connected.
294067: Total read: 1706
Total failures: 15/160
294070: Connected.
295853: Total read: 8346
Total failures: 15/161
295856: Connected.
297638: Total read: 8346
Total failures: 15/162
297641: Connected.
299424: Total read: 8346
Total failures: 15/163
299427: Connected.
301210: Total read: 8346
Total failures: 15/164
301214: Connected.
302998: Total read: 8346
Total failures: 15/165
303001: Connected.
305047: Total read: 4889
Total failures: 16/166
305050: Connected.
306833: Total read: 8346
Total failures: 16/167
306836: Connected.
308619: Total read: 8346
Total failures: 16/168
308622: Connected.
310405: Total read: 8346
Total failures: 16/169
310408: Connected.
312190: Total read: 8346
Total failures: 16/170
312194: Connected.
313977: Total read: 8346
Total failures: 16/171
313980: Connected.
315350: Total read: 1706
Total failures: 17/172
315353: Connected.
317135: Total read: 8346
Total failures: 17/173
317138: Connected.
319185: Total read: 4887
Total failures: 18/174
319188: Connected.
321173: Total read: 8346
Total failures: 18/175
321176: Connected.
323160: Total read: 8346
Total failures: 18/176
323163: Connected.
324945: Total read: 8346
Total failures: 18/177
324948: Connected.
326731: Total read: 8346
Total failures: 18/178
326734: Connected.
328104: Total read: 1706
Total failures: 19/179
328108: Connected.
329890: Total read: 8346
Total failures: 19/180
329893: Connected.
331877: Total read: 8346
Total failures: 19/181
331881: Connected.
333663: Total read: 8346
Total failures: 19/182
333667: Connected.
335450: Total read: 8346
Total failures: 19/183
335453: Connected.
337437: Total read: 8346
Total failures: 19/184
337440: Connected.
339094: Total read: 7740
Total failures: 20/185
339097: Connected.
340880: Total read: 8346
Total failures: 20/186
340883: Connected.
342666: Total read: 8346
Total failures: 20/187
342669: Connected.
344452: Total read: 8346
Total failures: 20/188
344455: Connected.
346097: Total read: 2989
Total failures: 21/189
346100: Connected.
347883: Total read: 8346
Total failures: 21/190
347886: Connected.
349933: Total read: 4890
Total failures: 22/191
349936: Connected.
351719: Total read: 8346
Total failures: 22/192
351722: Connected.
353705: Total read: 8346
Total failures: 22/193
353709: Connected.
355491: Total read: 8346
Total failures: 22/194
355494: Connected.
357277: Total read: 8346
Total failures: 22/195
357281: Connected.
359063: Total read: 8346
Total failures: 22/196
359067: Connected.
360850: Total read: 8346
Total failures: 22/197
360853: Connected.
362636: Total read: 8346
Total failures: 22/198
362639: Connected.
364423: Total read: 8346
Total failures: 22/199
364426: Connected.
366209: Total read: 8346
Total failures: 22/200
366212: Connected.
367664: Total read: 6790
Total failures: 23/201
367667: Connected.
369449: Total read: 8346
Total failures: 23/202
369453: Connected.
371235: Total read: 8346
Total failures: 23/203
371238: Connected.
373021: Total read: 8346
Total failures: 23/204
373024: Connected.
374807: Total read: 8346
Total failures: 23/205
374810: Connected.
376594: Total read: 8346
Total failures: 23/206
376597: Connected.
378380: Total read: 8346
Total failures: 23/207
378383: Connected.
380166: Total read: 8346
Total failures: 23/208
380169: Connected.
381822: Total read: 7739
Total failures: 24/209
381826: Connected.
383195: Total read: 1706
Total failures: 25/210
383198: Connected.
385181: Total read: 8346
Total failures: 25/211
385184: Connected.
386968: Total read: 8346
Total failures: 25/212
386971: Connected.
388816: Total read: 2994
Total failures: 26/213
388819: Connected.
390602: Total read: 8346
Total failures: 26/214
390605: Connected.
392388: Total read: 8346
Total failures: 26/215
392391: Connected.
394174: Total read: 8346
Total failures: 26/216
394177: Connected.
395960: Total read: 8346
Total failures: 26/217
395964: Connected.
397747: Total read: 8346
Total failures: 26/218
397750: Connected.
399533: Total read: 8346
Total failures: 26/219
399536: Connected.
401318: Total read: 8346
Total failures: 26/220
401321: Connected.
403104: Total read: 8346
Total failures: 26/221
403107: Connected.
405093: Total read: 8346
Total failures: 26/222
405096: Connected.
406879: Total read: 8346
Total failures: 26/223
406882: Connected.
408665: Total read: 8346
Total failures: 26/224
408668: Connected.
410450: Total read: 8346
Total failures: 26/225
410454: Connected.
412236: Total read: 8346
Total failures: 26/226
412239: Connected.
414022: Total read: 8346
Total failures: 26/227
414026: Connected.
415809: Total read: 8346
Total failures: 26/228
415812: Connected.
417595: Total read: 8346
Total failures: 26/229
417598: Connected.
419381: Total read: 8346
Total failures: 26/230
419384: Connected.
421167: Total read: 8346
Total failures: 26/231
421170: Connected.
423154: Total read: 8346
Total failures: 26/232
423157: Connected.
424940: Total read: 8346
Total failures: 26/233
424943: Connected.
426726: Total read: 8346
Total failures: 26/234
426729: Connected.
428715: Total read: 8346
Total failures: 26/235
428718: Connected.
430500: Total read: 8346
Total failures: 26/236
430503: Connected.
432286: Total read: 8346
Total failures: 26/237
432289: Connected.
434072: Total read: 8346
Total failures: 26/238
434075: Connected.
435858: Total read: 8346
Total failures: 26/239
435861: Connected.
437644: Total read: 8346
Total failures: 26/240
437647: Connected.
439430: Total read: 8346
Total failures: 26/241
439433: Connected.
441271: Total read: 8346
Total failures: 26/242
441274: Connected.
443320: Total read: 4890
Total failures: 27/243
443323: Connected.
445106: Total read: 8346
Total failures: 27/244
445109: Connected.
446953: Total read: 3939
Total failures: 28/245
446956: Connected.
448739: Total read: 8346
Total failures: 28/246
448742: Connected.
450525: Total read: 8346
Total failures: 28/247
450528: Connected.
452776: Total read: 4895
Total failures: 29/248
452780: Connected.
454562: Total read: 8346
Total failures: 29/249
454565: Connected.
456409: Total read: 3939
Total failures: 30/250
456412: Connected.
458194: Total read: 8346
Total failures: 30/251
458198: Connected.
460041: Total read: 3939
Total failures: 31/252
460044: Connected.
461827: Total read: 8346
Total failures: 31/253
461830: Connected.
463612: Total read: 8346
Total failures: 31/254
463616: Connected.
465398: Total read: 8346
Total failures: 31/255
465401: Connected.
467184: Total read: 8346
Total failures: 31/256
467187: Connected.
468829: Total read: 2989
Total failures: 32/257
468832: Connected.
470815: Total read: 8346
Total failures: 32/258
470818: Connected.
472601: Total read: 8346
Total failures: 32/259
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment