@@ -35,9 +35,10 @@ void setup() {
3535  IPAddress ip (192 , 168 , 10 , 130 );
3636  IPAddress gw (192 , 168 , 10 , 1 );
3737  IPAddress nm (255 , 255 , 255 , 0 );
38+   IPAddress dns (8 , 8 , 8 , 8 );
3839
3940  DEBUG_INFO (" Setting up netif" 
40-   Ethernet.begin (ip, nm, gw);
41+   Ethernet.begin (ip, nm, gw, dns );
4142  //  Ethernet.begin();
4243
4344  DEBUG_INFO (" Begin of reception\n\n " 
@@ -160,9 +161,9 @@ void reset_app(struct App& app) {
160161  }
161162}
162163
164+ uint16_t  bytes_read=0 ;
163165void  application () {
164166  bool  found = false ;
165-   uint16_t  bytes_read=0 ;
166167
167168  switch (app.current_state ) {
168169  case  APP_STATE_NONE:
@@ -189,8 +190,11 @@ void application() {
189190    //  The link is up we connect to the server
190191    app.tcp_client  = new  lwipClient;
191192
193+     memset (app.buffer , 0x66 , APP_BUFFER_SIZE);
194+ 
192195    //  Connection details:
193196    app.tcp_client ->connect (app.server_ip , app.port );
197+     //  app.tcp_client->connect("tcpbin.com", 4242);
194198
195199    app.prev_state  = app.current_state ;
196200    app.current_state  = APP_STATE_CONNECTING;
@@ -223,31 +227,35 @@ void application() {
223227      state_strings[app.prev_state ]);
224228    break ;
225229  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" 
228232
229-     if (res == sizeof (counter_t )) {
230-       app.counter ++;
233+     if (res == APP_BUFFER_SIZE) {
231234      app.prev_state  = app.current_state ;
232235      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 ]);
236239    }
237240    break ;
238241  }
239242  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);
242244
243-     if (bytes_read == sizeof (counter_t )) {
244-       DEBUG_INFO (" counter echoed, value 0x%08X" 
245+     if (res > 0 ) {
246+       bytes_read += res;
247+       DEBUG_INFO (" received %d bytes" 
248+     }
249+ 
250+     if (bytes_read == APP_BUFFER_SIZE) {
251+       DEBUG_INFO (" buffer received: %d" 
252+       bytes_read = 0 ;
245253
246254      app.prev_state  = app.current_state ;
247255      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 ]);
251259    }
252260    break ;
253261  }
0 commit comments