@@ -127,35 +127,40 @@ void processEthernetMessages()
127
127
// bytes available to read via the client object
128
128
EthernetClient client = server.available ();
129
129
130
- if (client)
130
+ if (client)
131
131
{
132
- // read the bytes incoming from the client
133
- char inChar = client.read ();
134
-
135
- // echo the bytes to the serial port
136
- Serial.print (inChar);
137
-
138
- if (inputPos<MAX_RECEIVE_LENGTH-1 ) {
139
- // if newline then command is complete
140
- if (inChar == ' \n ' )
141
- { // a command was issued by the client
142
- // we will now try to send it to the actuator
143
- inputString[inputPos] = 0 ;
144
- gw.parseAndSend (inputString);
145
-
146
- // clear the string:
132
+ // if got 1 or more bytes
133
+ if (client.available ())
134
+ {
135
+ // read the bytes incoming from the client
136
+ char inChar = client.read ();
137
+
138
+ if (inputPos<MAX_RECEIVE_LENGTH-1 ) {
139
+ // if newline then command is complete
140
+ if (inChar == ' \n ' )
141
+ { // a command was issued by the client
142
+ // we will now try to send it to the actuator
143
+ inputString[inputPos] = 0 ;
144
+
145
+ // echo the string to the serial port
146
+ Serial.print (inputString);
147
+
148
+ gw.parseAndSend (inputString);
149
+
150
+ // clear the string:
151
+ inputPos = 0 ;
152
+ }
153
+ else
154
+ { // add it to the inputString:
155
+ inputString[inputPos] = inChar;
156
+ inputPos++;
157
+ }
158
+ } else {
159
+ // Incoming message too long. Throw away
147
160
inputPos = 0 ;
148
161
}
149
- else
150
- { // add it to the inputString:
151
- inputString[inputPos] = inChar;
152
- inputPos++;
153
- }
154
- } else {
155
- // Incoming message too long. Throw away
156
- inputPos = 0 ;
157
- }
158
- }
162
+ }
163
+ }
159
164
}
160
165
161
166
0 commit comments