Add direct pin support using ESP201

This commit is contained in:
Luc 2016-09-28 10:45:31 +08:00
parent b3460b18f8
commit 9ccf1ec7ed
3 changed files with 59 additions and 0 deletions

View File

@ -44,6 +44,14 @@ if authentication is on, need admin password
* Get hostname
[ESP112]<header answer>
*Get/Set pin value
[ESP201]P<pin> V<value>
if no V<value> get P<pin> value
if V<value> 0/1 set INPUT_PULLUP value, but for GPIO16 INPUT_PULLDOWN_16
GPIO1 and GPIO3 cannot be used as they are used for serial
* Get/Set ESP mode
cmd can be RESET, SAFEMODE, CONFIG, RESTART
[ESP444]<cmd>

View File

@ -273,6 +273,54 @@ void COMMAND::execute_command(int cmd,String cmd_params)
Serial.print("\r\n");
}
break;
#ifdef DIRECT_PIN_FEATURE
//Get/Set pin value
//[ESP201]P<pin> V<value>
case 201: {
//check if have pin
parameter = get_param(cmd_params,"P", true);
LOG(parameter)
LOG("\n")
if (parameter == "")
{
Serial.println(INCORRECT_CMD_MSG);
}
else{
int pin = parameter.toInt();
//check pin is valid and not serial used pins
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3)))
{
//check if is set or get
parameter = get_param(cmd_params,"V", true);
//it is a get
if (parameter == "")
{ //GPIO16 is different than
if (pin <16) pinMode(pin, INPUT_PULLUP);
else pinMode(pin, INPUT_PULLDOWN_16);
delay(10);
int value = digitalRead(pin);
Serial.println(String(value));
}
else{
//it is a set
int value = parameter.toInt();
//verify it is a 0 or a 1
if ((value == 0) || (value == 1))
{
pinMode(pin, OUTPUT);
delay(10);
digitalWrite(pin, (value == 0)?LOW:HIGH);
}
else Serial.println(INCORRECT_CMD_MSG);
}
}
else Serial.println(INCORRECT_CMD_MSG);
}
}
break;
#endif
//Get/Set ESP mode
//cmd is RESET, SAFEMODE, CONFIG, RESTART
//[ESP444]<cmd>pwd=<admin password>

View File

@ -65,6 +65,9 @@
#define RESET_CONFIG_PIN 2
#endif
//DIRECT_PIN_FEATURE: allow to access pin using ESP201 command
#define DIRECT_PIN_FEATURE
//INFO_MSG_FEATURE: catch the Info msg and filter it to specific table
#define INFO_MSG_FEATURE