Skip to content

Commit 543b44b

Browse files
Version 2.0.0
Some big additions and updates plus changes to the API which may break old sketches.
1 parent 549bcd0 commit 543b44b

File tree

26 files changed

+989
-207
lines changed

26 files changed

+989
-207
lines changed

Changelog.txt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
Commander changelog
2-
Starting at 1.2.3
2+
(Changelog started at 1.2.3)
3+
4+
Commander 2.0.0
5+
6+
Re-worked several methods and method names and probably broke several things, for example setLockType(bool) replaces enableHardLock(), commandPrompt(bool) replaces enablePrompt() and disablePrompt(). Setting parameters like these are now all done by passing an argument, and macros for ON and OFF are defined.
7+
errorMessagesEnabled now controls all internal messages so disabling them will prevent replies from internal commands like 'echo' or 'U'
8+
bugfix: internal commands did not check length so, for example, sending helpaxfgqerg was recognised as a help command
9+
Added PRINT_LINE_DELAY macro - if defined at the start of a sketch it will insert the defined marco before a line of text is printed - used to slow down transmission when sending many lines of data so a slow reciever can handle it.
10+
Added a defaultHandler function pointer that will be called whenever an unknown command is found. The user can now attach their own command handler for dealing with unrecognised commands. If not specified, the internal handler will be used.
11+
Added a method that returns the number of items in the command list.
12+
Added a method to return a String with the command help text for a specified item in the command list.
13+
Added a method that returns the number of items in the internal command list.
14+
Added a method to return a String with the command and help text for a specified item in the internal command list.
15+
Added a hide Internal Commands bit to prevent internal commands being displayed in help.
16+
Added an enable internal commands bit to stop internal commands from working.
17+
Added getString() method to extract sequential strings seperated by a space or special delimiter
18+
Added a countItems method to return the number of items in the payload. An idem is defined as a string with a space or delimChar at each end (or an end of line char)
19+
Renamed the eocChar into a delimChar, it is used as a delimiter between any items in the payload alongside the space character
20+
Added methods to set the delimChar and endOfLine char.
21+
Added two bit StreamType code to indicate if the attached stream is a serial port, file or web - this is to allow handlers to interrogate the Commander object calling the handler to adjust its response for that stream, for example by adding formatting to a response.
22+
Methods containsOn and containsTrue now work for both lower case and capitals.
23+
Updated the basic example sketch to demonstrate countItems() and getString() methods. These count and display all items in the payload.
24+
Added an HTML web server example using Commander to deliver formatted web pages.
25+
Removed updatePending() because this function is prformed within update()
26+
27+
Utilities:
28+
Added a function to convert an HTTP GET line to a command string - It finds the start and end of the GET message and converts and / or + chars to spaces. A line with "GET /help HTTP/1.1" will return a string containing "help" or "GET /setLED/on HTTP/1.1" will return "setLED on" The function can return a default string if nothing is found.
29+
String GET_CommandString(String serverGetLine, String defaultString)
30+
31+
Commander 1.3.2:
32+
Changed getInt() to a template method so it will work for any int type (byte, long, unsigned etc)
333

434
Commander 1.3.1:
535
Restructured directories so everything is in src
@@ -13,4 +43,4 @@ Minor edits to readme
1343
Changes to how help is formatted
1444

1545
Commander 1.2.3:
16-
Added enable bit for help system and query command. The help system an now be disabled if required.
46+
Added enable bit for help system and query command. The help system can now be disabled if required.

examples/BasicCommands/BasicCommands.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ float myFloat = 0.0;
1313
void setup() {
1414
Serial.begin(115200);
1515
cmd.begin(&Serial, masterCommands, numOfMasterCmds);
16-
cmd.enablePrompt(); //enable the command prompt
16+
cmd.commandPrompt(ON); //enable the command prompt
1717
cmd.echo(true); //Echo incoming characters to theoutput port
18-
cmd.enableErrors(); //error messages are enabled - it will tell us if we issue any unrecognised commands
18+
cmd.errorMessages(ON); //error messages are enabled - it will tell us if we issue any unrecognised commands
1919

2020
while(!Serial){;}
2121
Serial.println("Hello: Type 'help' to get help");

examples/BasicCommands/masterCommands.ino

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
//All commands for 'master'
22
//COMMAND ARRAY ------------------------------------------------------------------------------
33
const commandList_t masterCommands[] = {
4-
{"hello", helloHandler, "hello"},
5-
{"get int", getIntHandler, "get an int"},
6-
{"set int", setIntHandler, "set an int"},
7-
{"get float", getFloatHandler, "get a float"},
8-
{"set float", setFloatHandler, "set a float"},
9-
{"myint", setIntHandler, "try myint=23"},
10-
{"myfloat", setFloatHandler, "try myfloat=23.5"},
11-
{"set ints", getIntsHandler, "set up to four ints"},
12-
{"set floats", getFloatsHandler, "set up to four floats"},
4+
{"hello", helloHandler, "hello"},
5+
{"get int", getIntHandler, "get an int"},
6+
{"set int", setIntHandler, "set an int"},
7+
{"get float", getFloatHandler, "get a float"},
8+
{"set float", setFloatHandler, "set a float"},
9+
{"myint", setIntHandler, "try myint=23"},
10+
{"myfloat", setFloatHandler, "try myfloat=23.5"},
11+
{"set ints", setIntsHandler, "set up to four ints"},
12+
{"set floats", setFloatsHandler, "set up to four floats"},
13+
{"set strings", setStringsHandler,"set up to four Strings"},
1314
};
1415
/*
1516
* This needs to be passed to the commander object so it knows how big the array of commands is, but this happens earlier in setup().
@@ -61,9 +62,15 @@ bool setFloatHandler(Commander &Cmdr){
6162
return 0;
6263
}
6364

64-
bool getIntsHandler(Commander &Cmdr){
65+
bool setIntsHandler(Commander &Cmdr){
6566
//create an array to store any values we find
6667
int values[4] = {0,0,0,0};
68+
69+
int itms = Cmdr.countItems();
70+
Cmdr.print("There are ");
71+
Cmdr.print(itms);
72+
Cmdr.println(" items in the payload");
73+
6774
for(int n = 0; n < 4; n++){
6875
//try and unpack an int, if it fails there are no more left so exit the loop
6976
if(Cmdr.getInt(values[n])){
@@ -81,20 +88,41 @@ bool getIntsHandler(Commander &Cmdr){
8188
return 0;
8289
}
8390

84-
bool getFloatsHandler(Commander &Cmdr){
91+
bool setFloatsHandler(Commander &Cmdr){
8592
float values[4] = {0.0,0.0,0.0,0.0};
86-
int n = 0;
87-
for(n = 0; n < 4; n++){
93+
int itms = Cmdr.countItems();
94+
Cmdr.print("There are ");
95+
Cmdr.print(itms);
96+
Cmdr.println(" items in the payload");
97+
98+
for(int n = 0; n < 4; n++){
8899
if(Cmdr.getFloat(values[n])){
89100
Cmdr.print("unpacked ");
90101
Cmdr.println(values[n]);
91102
}else break;
92103
}
93104
Cmdr.println("Array contents after processing:");
94-
for(n = 0; n < 4; n++){
105+
for(int n = 0; n < 4; n++){
95106
Cmdr.print(n);
96107
Cmdr.print(" = ");
97108
Cmdr.println(values[n]);
98109
}
99110
return 0;
100111
}
112+
113+
bool setStringsHandler(Commander &Cmdr){
114+
String myString = "";
115+
int itms = Cmdr.countItems();
116+
Cmdr.print("There are ");
117+
Cmdr.print(itms);
118+
Cmdr.println(" items in the payload");
119+
for(int n = 0; n < itms; n++){
120+
if(Cmdr.getString(myString)){
121+
Cmdr.print("String ");
122+
Cmdr.print(n);
123+
Cmdr.print(" = ");
124+
Cmdr.println(myString);
125+
}else Cmdr.println("Operation failed");
126+
}
127+
return 0;
128+
}

examples/ESP32/SerialBTCommands/SerialBTCommands.ino

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,11 @@ void setup() {
2525
Serial.println("The device started, now you can pair it with bluetooth!");
2626

2727
cmd.begin(&SerialBT, masterCommands, numOfMasterCmds);
28-
cmd.enablePrompt(); //enable the command prompt
29-
//cmd.echo(true); //Echo incoming characters to the output port
30-
cmd.enableErrors(); //error messages are enabled - it will tell us if we issue any unrecognised commands
31-
//while(!Serial){;}
32-
//Serial.println("Hello: Type 'help' to get help");
28+
cmd.commandPrompt(ON);; //enable the command prompt
3329
cmd.printCommandPrompt();
3430
}
3531

3632
void loop() {
3733
cmd.update();
38-
/*if (Serial.available()) {
39-
SerialBT.write(Serial.read());
40-
}
41-
if (SerialBT.available()) {
42-
Serial.write(SerialBT.read());
43-
}*/
4434
delay(20);
4535
}

examples/ESP32/TelnetCommands/TelnetCommands.ino

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ void setup() {
5858

5959

6060
cmd.begin(&serverClient, masterCommands, numOfMasterCmds);
61-
cmd.enablePrompt(); //enable the command prompt
62-
//cmd.echo(true); //Echo incoming characters to the output port
63-
cmd.enableErrors(); //error messages are enabled - it will tell us if we issue any unrecognised commands
64-
//while(!Serial){;}
65-
//Serial.println("Hello: Type 'help' to get help");
61+
cmd.commandPrompt(ON);; //enable the command prompt
6662
cmd.printCommandPrompt();
6763
}
6864

@@ -77,9 +73,7 @@ void loop() {
7773
serverClient = server.available();
7874
if (!serverClient) Serial.println("available broken");
7975
Serial.print("New client: ");
80-
Serial.print(i); Serial.print(' ');
8176
Serial.println(serverClient.remoteIP());
82-
break;
8377
}
8478
}
8579
//check clients for data
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
//connect to VM4789902 vrtqvfDxr8hq
2+
//connect to AndroidAP hvpm2495
3+
4+
//bool query(serialBuffer_t &sBuff);
5+
//bool help(serialBuffer_t &sBuff);
6+
7+
const commandList_t Commands[] = {
8+
{"set help", setHelpState, "help sys on or off"},
9+
{"set internal", setIntCmdState, "internal cmds on or off"},
10+
{"show internal", hideIntCmd, "internal cmds print on or off"},
11+
{"enable server", startEnableServer, "enable web server"},
12+
{"disable server", disableServer, "disable web server"},
13+
{"set SSID", setSSID, "set WiFI SSID"}, //setSSID0=
14+
{"set Pass", setPassword, "set WiFi password"}, //setWiFiPass0=
15+
{"connect to", wifiConnectTo, "connect to WiFI (SSID) (Password)"},
16+
{"set WiFi Timeout", setWiFiTimeout, "set WiFi connect timeout"}, //setWiFiPass0=
17+
{"hello", helloHandler, "say hello"}, //setWiFiPass0=
18+
{"webhelp", callHelp, "call help www style"}, //setWiFiPass0=
19+
{"test", callTest, "Show the test page"}, //setWiFiPass0=
20+
{"homework", callHomework, "Show homework page"}, //setWiFiPass0=
21+
{"robots.txt", callRobots, "Robots page"}, //setWiFiPass0=
22+
{"?", query, "query"}, //setWiFiPass0=
23+
};
24+
const uint16_t numOfCmds = sizeof(Commands);// / sizeof(ESPCommands[0]); //calculate the number of commands so we know the array bounds
25+
26+
27+
28+
const commandList_t WiFiCommands[] = {
29+
{"hello", helloHandler, "say hello"}, //setWiFiPass0=
30+
{"help", callHelp, "call help"}, //setWiFiPass0=
31+
{"test", callTest, "Show the test page"}, //setWiFiPass0=
32+
{"homework", callHomework, "Show homework page"}, //setWiFiPass0=
33+
{"robots.txt", callRobots, "Robots page"}, //setWiFiPass0=
34+
{"?", query, "query"}, //setWiFiPass0=
35+
};
36+
const uint16_t numOfWiFICmds = sizeof(WiFiCommands);// / sizeof(ESPCommands[0]); //calculate the number of commands so we know the array bounds
37+
38+
39+
//Serial port command handlers ======================================================================================================
40+
//Default handler - for error messages
41+
42+
43+
44+
bool setHelpState(Commander &Cmdr){
45+
if(Cmdr.containsOn()){
46+
Cmdr.enableHelp();
47+
Cmdr.println("Help Visible");
48+
}else{
49+
Cmdr.disableHelp();
50+
51+
Cmdr.println("Help hidden");
52+
}
53+
return 0;
54+
}
55+
bool setIntCmdState(Commander &Cmdr){
56+
if(Cmdr.containsOn()){
57+
Cmdr.enableInternalCommands();
58+
Cmdr.println("Int cmds ON");
59+
}else{
60+
Cmdr.disableInternalCommands();
61+
62+
Cmdr.println("Int cmds OFF");
63+
}
64+
return 0;
65+
}
66+
67+
bool hideIntCmd(Commander &Cmdr){
68+
if(Cmdr.containsOn()){
69+
Cmdr.enableInternalCommandPrint();
70+
Cmdr.println("Int cmds visible");
71+
}else{
72+
Cmdr.disableInternalCommandPrint();
73+
74+
Cmdr.println("Int cmds hidden");
75+
}
76+
return 0;
77+
}
78+
bool callRobots(Commander &Cmdr){
79+
80+
Cmdr.print(robotsPage);
81+
return 0;
82+
}
83+
84+
85+
bool defaultHandler(Commander &Cmdr){
86+
Serial.println("Default Handler called");
87+
Cmdr.print(cmdHeadErrorPage);
88+
for(uint16_t n = 0; n < Cmdr.getCommandListLength(); n++){
89+
Cmdr.println(Cmdr.getCommandItem(n));
90+
}
91+
Cmdr.print(cmdForm);
92+
Cmdr.print(cmdFootPage);
93+
return 0;
94+
}
95+
bool helloHandler(Commander &Cmdr){
96+
97+
Cmdr.print(helloPage);
98+
return 0;
99+
}
100+
bool callHomework(Commander &Cmdr){
101+
102+
Cmdr.print(myHomework);
103+
return 0;
104+
}
105+
bool callTest(Commander &Cmdr){
106+
107+
Cmdr.print(testPage);
108+
return 0;
109+
}
110+
bool callHelp(Commander &Cmdr){
111+
112+
//cmdWiFi.setAutoFormat(false);
113+
Cmdr.print(cmdHeadPage);
114+
for(uint16_t n = 0; n < Cmdr.getCommandListLength(); n++){
115+
Cmdr.println(Cmdr.getCommandItem(n));
116+
}
117+
//Cmdr.printCommandList();
118+
Cmdr.print(cmdForm);
119+
Cmdr.print(cmdFootPage);
120+
//cmdWiFi.setAutoFormat(true);
121+
return 0;
122+
}
123+
bool query(Commander &Cmdr){
124+
Cmdr.startFormatting();
125+
Cmdr.printCommanderVersion();
126+
return 0;
127+
}
128+
bool setWiFiTimeout(Commander &Cmdr){
129+
if( Cmdr.getInt(wifiConnectTimeout) ){
130+
if(wifiConnectTimeout < 10) wifiConnectTimeout = 10;
131+
}
132+
return 0;
133+
}
134+
135+
136+
137+
bool wifiConnectTo(Commander &Cmdr){
138+
if(DEBUGGING) DEBUG.println("Trying to connect to ...");
139+
Cmdr.getString(myssid);
140+
Cmdr.getString(password);
141+
if(DEBUGGING) {DEBUG.print("SSID=["); DEBUG.print(myssid); DEBUG.println(']');}
142+
if(DEBUGGING) {DEBUG.print("PSWD=["); DEBUG.print(password); DEBUG.println(']');}
143+
return 0;
144+
}
145+
146+
bool wifiDisconnect(Commander &Cmdr){
147+
WiFi.mode(WIFI_OFF);
148+
Cmdr.println("WiFi Disconnected");
149+
}
150+
151+
152+
bool setSSID(Commander &Cmdr){
153+
if(DEBUGGING) DEBUG.println("Setting SSID");
154+
if(Cmdr.hasPayload()){
155+
myssid = Cmdr.getPayloadString();
156+
}
157+
if(DEBUGGING){
158+
DEBUG.print("Set SSID to: ");
159+
DEBUG.println(myssid);
160+
}
161+
return 0;
162+
}
163+
164+
bool setPassword(Commander &Cmdr){
165+
if(DEBUGGING) DEBUG.println("Setting Password");
166+
if(Cmdr.hasPayload()){
167+
password = Cmdr.getPayloadString();
168+
}
169+
if(DEBUGGING){
170+
Cmdr.print("Set Password to: ");
171+
Cmdr.println(password);
172+
}
173+
return 0;
174+
}
175+
bool startEnableServer(Commander &Cmdr){
176+
server.begin();
177+
return 0;
178+
}
179+
180+
bool disableServer(Commander &Cmdr){
181+
server.end();
182+
return 0;
183+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html><html><body>
2+
<form action="/action_page.php">
3+
<p>Enactive Torch RT Configuration page.</p>
4+
<form action="CONFIGURE">
5+
Device Name: <input type="text" name="DeviceName" value="ETRT2.0 The NEw One!"><br>
6+
Bluetooth Name: <input type="text" name="BTName" value="ETRT2:01"><br>
7+
Streaming Port: <input type="text" name="StreamingPort" value="80"><br>
8+
<input type="submit" value="Submit">
9+
</form>
10+
<p>Click the "Submit\ button and the form-data will be sent to the device with the heading "CONFIGURE".</p>
11+
<br>
12+
<form action="PARTYTIME">
13+
Party Name: <input type="text" name="PartyName" value="Hector"><br>
14+
Disguise: <input type="text" name="Disguise" value="Rabbit"><br>
15+
Value: <input type="text" name="Value" value="1000000"><br>
16+
</body></html>

0 commit comments

Comments
 (0)