@@ -35,9 +35,10 @@ void setup() {
35
35
IPAddress ip (192 , 168 , 10 , 130 );
36
36
IPAddress gw (192 , 168 , 10 , 1 );
37
37
IPAddress nm (255 , 255 , 255 , 0 );
38
+ IPAddress dns (8 , 8 , 8 , 8 );
38
39
39
40
DEBUG_INFO (" Setting up netif" );
40
- Ethernet.begin (ip, nm, gw);
41
+ Ethernet.begin (ip, nm, gw, dns );
41
42
// Ethernet.begin();
42
43
43
44
DEBUG_INFO (" Begin of reception\n\n " );
@@ -160,9 +161,9 @@ void reset_app(struct App& app) {
160
161
}
161
162
}
162
163
164
+ uint16_t bytes_read=0 ;
163
165
void application () {
164
166
bool found = false ;
165
- uint16_t bytes_read=0 ;
166
167
167
168
switch (app.current_state ) {
168
169
case APP_STATE_NONE:
@@ -189,8 +190,11 @@ void application() {
189
190
// The link is up we connect to the server
190
191
app.tcp_client = new lwipClient;
191
192
193
+ memset (app.buffer , 0x66 , APP_BUFFER_SIZE);
194
+
192
195
// Connection details:
193
196
app.tcp_client ->connect (app.server_ip , app.port );
197
+ // app.tcp_client->connect("tcpbin.com", 4242);
194
198
195
199
app.prev_state = app.current_state ;
196
200
app.current_state = APP_STATE_CONNECTING;
@@ -223,31 +227,35 @@ void application() {
223
227
state_strings[app.prev_state ]);
224
228
break ;
225
229
case APP_STATE_SEND: {
226
- int res = app.tcp_client ->write (( uint8_t *)& app.counter , sizeof ( counter_t ) );
227
- DEBUG_INFO (" counter sent, value 0x%08X, res: %d" , app. counter , res);
230
+ int res = app.tcp_client ->write (app.buffer , APP_BUFFER_SIZE );
231
+ DEBUG_INFO (" buffer sent res: %d" , res);
228
232
229
- if (res == sizeof (counter_t )) {
230
- app.counter ++;
233
+ if (res == APP_BUFFER_SIZE) {
231
234
app.prev_state = app.current_state ;
232
235
app.current_state = APP_STATE_RECEIVE;
233
- // DEBUG_INFO("State changed: to %s, from %s",
234
- // state_strings[app.current_state],
235
- // state_strings[app.prev_state]);
236
+ DEBUG_INFO (" State changed: to %s, from %s" ,
237
+ state_strings[app.current_state ],
238
+ state_strings[app.prev_state ]);
236
239
}
237
240
break ;
238
241
}
239
242
case APP_STATE_RECEIVE: {
240
- counter_t read_counter;
241
- bytes_read = app.tcp_client ->read ((uint8_t *)&read_counter, sizeof (counter_t ));
243
+ int res = app.tcp_client ->read (app.buffer , APP_BUFFER_SIZE);
242
244
243
- if (bytes_read == sizeof (counter_t )) {
244
- DEBUG_INFO (" counter echoed, value 0x%08X" , read_counter);
245
+ if (res > 0 ) {
246
+ bytes_read += res;
247
+ DEBUG_INFO (" received %d bytes" , res);
248
+ }
249
+
250
+ if (bytes_read == APP_BUFFER_SIZE) {
251
+ DEBUG_INFO (" buffer received: %d" , bytes_read);
252
+ bytes_read = 0 ;
245
253
246
254
app.prev_state = app.current_state ;
247
255
app.current_state = APP_STATE_SEND;
248
- // DEBUG_INFO("State changed: to %s, from %s",
249
- // state_strings[app.current_state],
250
- // state_strings[app.prev_state]);
256
+ DEBUG_INFO (" State changed: to %s, from %s" ,
257
+ state_strings[app.current_state ],
258
+ state_strings[app.prev_state ]);
251
259
}
252
260
break ;
253
261
}
0 commit comments