Skip to content

Commit e822e58

Browse files
committed
ESP Example Fix
1 parent 3cce1f0 commit e822e58

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

.github/workflows/compile-examples.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,25 @@ jobs:
4141
4242
sketch-paths: |
4343
- examples/Commander_simple_ESP32
44+
45+
compile-examples-for-esp8266:
46+
runs-on: ubuntu-latest
47+
48+
strategy:
49+
matrix:
50+
fqbn:
51+
- esp8266:esp8266:esp8266
52+
53+
steps:
54+
- uses: actions/checkout@v3
55+
- uses: arduino/compile-sketches@v1
56+
with:
57+
fqbn: ${{ matrix.fqbn }}
58+
59+
platforms: |
60+
- name: esp32:ESP32
61+
source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
62+
63+
64+
sketch-paths: |
65+
- examples/Commander_simple_ESP8266

examples/Commander_simple_ESP32/Commander_simple_ESP32.ino

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include "Commander-API.hpp"
1616
#include "Commander-IO.hpp"
1717

18+
// This example assumes that there is a LED on GPIO-2,
19+
// like on ESP32 NodeMCU boards.
20+
#define LED_PIN 2
1821

1922
// We have to create an object from Commander class.
2023
Commander commander;
@@ -59,8 +62,8 @@ WiFiServer server( SERVER_PORT );
5962
void setup() {
6063

6164
// Set the LED pin to output, and turn it off.
62-
pinMode( LED_BUILTIN, OUTPUT );
63-
digitalWrite( LED_BUILTIN, 0 );
65+
pinMode( LED_PIN, OUTPUT );
66+
digitalWrite( LED_PIN, 0 );
6467

6568
// In this example, we will use the Serial for communication,
6669
// so we have to initialize it.
@@ -322,7 +325,7 @@ void dog_func(char *args, commandResponse *response )
322325
void led_func(char *args, commandResponse *response )
323326
{
324327

325-
digitalWrite( LED_BUILTIN, !digitalRead( LED_BUILTIN ) );
328+
digitalWrite( LED_PIN, !digitalRead( LED_PIN ) );
326329

327330
}
328331

examples/Commander_simple_ESP8266/Commander_simple_ESP8266.ino

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
* This file is part of the Commander-API project.
77
* Modified 2022.04.24
8-
*
8+
*
99
* This is a simple example sketch that shows how
1010
* to use Commander-API library.
1111
*/
@@ -15,6 +15,10 @@
1515
#include "Commander-API.hpp"
1616
#include "Commander-IO.hpp"
1717

18+
// This example assumes that there is a LED on GPIO-2,
19+
// like on ESP32 NodeMCU boards.
20+
#define LED_PIN 2
21+
1822
// We have to create an object from Commander class.
1923
Commander commander;
2024

@@ -58,16 +62,16 @@ WiFiServer server( SERVER_PORT );
5862
void setup() {
5963

6064
// Set the LED pin to output, and turn it off.
61-
pinMode( LED_BUILTIN, OUTPUT );
62-
digitalWrite( LED_BUILTIN, 0 );
63-
65+
pinMode( LED_PIN, OUTPUT );
66+
digitalWrite( LED_PIN, 0 );
67+
6468
// In this example we will use the Serial for communication,
6569
// so we have to initialize it.
6670
Serial.begin( 115200 );
6771

6872
// Step 1.
6973
Serial.println( "Step 1." );
70-
74+
7175
// There is an option to attach a debug channel to Commander.
7276
// It can be handy to find any problems during the initialization
7377
// phase. In this example we will use Serial for this.
@@ -99,7 +103,7 @@ void setup() {
99103
// To execute a command we have to use the execute command. Let's try
100104
// the led command. This command just toggles the built-in LED.
101105
commander.execute( "led" );
102-
106+
103107
// Example 2.
104108
Serial.println();
105109
Serial.println( "Example 2." );
@@ -184,10 +188,10 @@ void setup() {
184188
Serial.println( SERVER_PORT );
185189
Serial.println( "Now you can play with commander with serial port or with socket." );
186190
Serial.println( "To try socket communication I suggest PuTTY." );
187-
191+
188192

189193
server.begin();
190-
194+
191195
}
192196

193197
// Continous example.
@@ -214,48 +218,48 @@ void loop() {
214218
while( client.connected() ){
215219

216220
while( client.available() ){
217-
221+
218222
// Read the next incoming character.
219223
c = client.read();
220-
224+
221225
// Every command from Serial is terminated with a new-line
222226
// character. If a new-line character arrives we have to
223227
// terminate the string in the commandFromSerial buffer,
224228
// and execute it. After execution we have to reset the
225229
// commandIndex counter to zero.
226230
if( c == '\n' ){
227-
231+
228232
commandFromSerial[ commandIndex ] = '\0';
229233
commander.execute( commandFromSerial, &client );
230234
commandIndex = 0;
231-
235+
232236
}
233-
237+
234238
// If we have a carriage-return character we simply
235239
// ignore it.
236240
else if( c == '\r' ){
237241
continue;
238242
}
239-
243+
240244
// Every other case we just put the data to the next
241245
// free space in the commandFromSerial buffer, increment
242246
// the commandIndex, and check if it want's to overflow.
243247
else{
244-
248+
245249
commandFromSerial[ commandIndex ] = c;
246250
commandIndex++;
247251
if( commandIndex >= 20 ){
248252
commandIndex = 19;
249253
}
250-
254+
251255
}
252-
256+
253257
}
254258

255259
delay( 10 );
256-
260+
257261
}
258-
262+
259263
}
260264

261265
// Check if there is any data incoming.
@@ -274,7 +278,7 @@ void loop() {
274278
commandFromSerial[ commandIndex ] = '\0';
275279
commander.execute( commandFromSerial, &Serial );
276280
commandIndex = 0;
277-
281+
278282
}
279283

280284
// If we have a carriage-return character we simply
@@ -293,9 +297,9 @@ void loop() {
293297
if( commandIndex >= 20 ){
294298
commandIndex = 19;
295299
}
296-
300+
297301
}
298-
302+
299303
}
300304

301305
}
@@ -321,7 +325,7 @@ void dog_func(char *args, commandResponse *response )
321325
void led_func(char *args, commandResponse *response )
322326
{
323327

324-
digitalWrite( LED_BUILTIN, !digitalRead( LED_BUILTIN ) );
328+
digitalWrite( LED_PIN, !digitalRead( LED_PIN ) );
325329

326330
}
327331

@@ -353,7 +357,7 @@ void sum_func(char *args, commandResponse *response )
353357

354358
// Sadly we have to stop the command execution and return.
355359
return;
356-
360+
357361
}
358362

359363
// Calculate the sum.

0 commit comments

Comments
 (0)