flair писал(а):дайте скетч посмотреть....
мой пример под мой скетч....
command_t const gCommandTable[COMMAND_TABLE_SIZE] = {
// {"LED", commandsLed, },
{"HELP", commandsHelp, }, // Выводит список комманд (вызов
http://xx.xx.xx.xx/command?8=HELP )
{"ON", commandsOn, }, // Устанавливает "1" на заданном цифровом порту (вызов
http://xx.xx.xx.xx/command?8=ON )
{"OFF", commandsOff, }, // Устанавливает "0" на заданном цифровом порту (вызов
http://xx.xx.xx.xx/command?8=OFF )
{"STATUS", commandsStatus, }, // Получить состояние цифрового порта (1 или 0) (вызов
http://xx.xx.xx.xx/command?8=STATUS ),
// если вместо номера порта передать ALL (вызов
http://xx.xx.xx.xx/command?ALL=STATUS ), то получим состояние всех портов (Пример вывода P3=0;P4=0;P5=0;P6=0;P7=0;P8=1;P9=1;)
{"TEMP", commandsTemp, }, // Получить температуры цифрового датчика (также влажность) (вызов
http://xx.xx.xx.xx/command?8=TEMP ),
{"CLICK", commandsClick, }, // Кратковременная "1" на порту 1сек (время настраивается) (вызов
http://xx.xx.xx.xx/command?8=CLICK )
{"LCLICK", commandsLClick, }, // Кратковременная "1" на порту 3сек (время настраивается) (вызов
http://xx.xx.xx.xx/command?8=LCLICK )
{NULL, NULL }
};
void cliProcessCommand(WebServer &server)
{
int bCommandFound = false;
int idx;
gParamValue = strtol(gParamBuffer, NULL, 0); // Convert the parameter to an integer value. If the parameter is empty, gParamValue becomes 0.
for (idx = 0; gCommandTable[idx].name != NULL; idx++) { // Search for the command in the command table until it is found or the end of the table is reached. If the command is found, break out of the loop.
if (strcmp(gCommandTable[idx].name, gCommandBuffer) == 0) {
bCommandFound = true;
break;
}
}
if (bCommandFound == true) { // Если команда найдена (в массиве команд), то выполняем ее. Если нет - игнорируем
(*gCommandTable[idx].function)(server);
}
else { // Command not found
server.print("ERROR: Command not found");
}
}
/**********************************************************************************************************************/
/* Обработчики команд */
void commandsOn(WebServer &server) {
if ((gParamValue=46) && (RelayPumpStatusNow == 0)) {
RelayPumpStatusNow = !RelayPumpStatusNow;
}
else if ((gParamValue=47) && (RelayConvStatusNow == 0)) {
RelayConvStatusNow = !RelayConvStatusNow;
}
else ErrorMessage(server);
}
void commandsOff(WebServer &server) {
if ((gParamValue=46) && (RelayPumpStatusNow == 1) && PumpPrior == 0) {
RelayPumpStatusNow = !RelayPumpStatusNow;
}
else if ((gParamValue=47) && (RelayConvStatusNow == 1)) {
RelayConvStatusNow = !RelayConvStatusNow;
}
else ErrorMessage(server);
}
void commandsClick(WebServer &server) {
if (gParamValue>=startPin && gParamValue<=endPin) {
digitalWrite(gParamValue,HIGH);
delay(delayClick);
digitalWrite(gParamValue,LOW);
} else ErrorMessage(server);
}
void commandsLClick(WebServer &server) {
if (gParamValue>=startPin && gParamValue<=endPin) {
digitalWrite(gParamValue,HIGH);
delay(delayLClick);
digitalWrite(gParamValue,LOW);
} else ErrorMessage(server);
}
void commandsStatus(WebServer &server) {
if (strcmp(gParamBuffer, "ALL") == 0) { // выдать состояние всех пинов
for(int i=startPin;i<=endPin;i++) {
int st=digitalRead(i);
char my_st[5];
itoa(st,my_st,10);
server.print("P");
server.print(i);
server.print("=");
server.print(my_st);
server.print(";");
}
} else { // выдать состояние только 1 пина
if (gParamValue>=startPin && gParamValue<=endPin) {
server.print("P");
server.print(gParamValue);
server.print("=");
server.print(digitalRead(gParamValue));
} else ErrorMessage(server);
}
}
void commandsTemp(WebServer &server) {
float t1 = sens.readTemperature(44);
float h1 = sens.readHumidity(44);
delay(1000);
float t2 = sens.readTemperature(45);
float h2 = sens.readHumidity(45);
delay(1000);
if (gParamValue>= 44 && gParamValue<= 45) {
server.print("<hr>Temp=");
server.print(sens.readTemperature (gParamValue));
server.print("<hr>Humidity=");
server.print(sens.readHumidity(gParamValue));
}
else ErrorMessage(server);
}
void commandsHelp(WebServer &server) {
int idx;
for (idx = 0; gCommandTable[idx].name != NULL; idx++) {
server.print(gCommandTable[idx].name);
server.print("<br>");
}
}