first steps working webcall output :)
This commit is contained in:
parent
4438aba304
commit
21104837ff
4 changed files with 63 additions and 7 deletions
Arduino/CanGrow
|
@ -38,6 +38,8 @@
|
|||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <WiFiClient.h>
|
||||
#endif
|
||||
|
||||
// * ESP32 *
|
||||
|
@ -45,6 +47,7 @@
|
|||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include <Update.h>
|
||||
#include <HTTPClient.h>
|
||||
#endif
|
||||
|
||||
#include <WiFiUdp.h>
|
||||
|
|
|
@ -137,6 +137,54 @@ byte Output_GPIO_Init_Update(const byte GPIOindexId, const bool PWM, const bool
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool Output_Webcall_Init_Update(const byte OutputId, const bool Value = false) {
|
||||
const static char LogLoc[] PROGMEM = "[Output:Webcall:Init_Update]";
|
||||
|
||||
/* here we invert the value if set. First we hand it to a tmp var, Value_tmp */
|
||||
bool Value_tmp = Value;
|
||||
/* check if output has inverted flagged */
|
||||
if(config.system.output.invert[OutputId] == true)
|
||||
Value_tmp = 1 - Value;
|
||||
|
||||
|
||||
String url;
|
||||
url += "http://";
|
||||
url += config.system.output.webcall_host[OutputId];
|
||||
url += "/";
|
||||
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
|
||||
switch(Value_tmp) {
|
||||
/* turn on */
|
||||
case true:
|
||||
url += config.system.output.webcall_path_on[OutputId];
|
||||
break;
|
||||
|
||||
/* turn off */
|
||||
case false:
|
||||
url += config.system.output.webcall_path_off[OutputId];
|
||||
break;
|
||||
}
|
||||
|
||||
/* build request */
|
||||
http.begin(client, url);
|
||||
|
||||
/* fire request and check result, */
|
||||
int httpResponseCode = http.GET();
|
||||
/* if 200 , OK */
|
||||
if(httpResponseCode > 0) {
|
||||
Log.verbose(F("%s http get success - %d" CR), LogLoc, httpResponseCode);
|
||||
return true;
|
||||
} else {
|
||||
Log.verbose(F("%s http get FAILED - %d" CR), LogLoc, httpResponseCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Output_Init() {
|
||||
/* initialize all configured outputs */
|
||||
const static char LogLoc[] PROGMEM = "[Output:Init]";
|
||||
|
@ -187,7 +235,8 @@ void Output_Init() {
|
|||
config.system.output.enabled[i], config.system.output.gpio_pwm[i], config.system.output.invert[i]);
|
||||
#endif
|
||||
/* TODO implement webcall init */
|
||||
outputStatus[i] = true;
|
||||
outputStatus[i] = Output_Webcall_Init_Update(i);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -219,6 +268,7 @@ void Output_Update() {
|
|||
|
||||
case OUTPUT_TYPE_WEB:
|
||||
/* TODO implement webcall init */
|
||||
outputStatus[i] = Output_Webcall_Init_Update(i);
|
||||
true;
|
||||
break;
|
||||
|
||||
|
|
|
@ -32,7 +32,9 @@ const char * Output_Type_descr[] = {
|
|||
const byte OUTPUT_GPIO_IU_MODE_INIT = 0;
|
||||
const byte OUTPUT_GPIO_IU_MODE_UPDATE = 1;
|
||||
|
||||
|
||||
/* Output_Webcall_Addr_Init_Update() modes */
|
||||
const byte OUTPUT_WEB_IU_MODE_INIT = 0;
|
||||
const byte OUTPUT_WEB_IU_MODE_UPDATE = 1;
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -785,6 +785,12 @@ void WebPage_system_output_add(AsyncWebServerRequest *request) {
|
|||
const AsyncWebParameter* param = request->getParam("enabled", true);
|
||||
config.system.output.enabled[outputId] = param->value().toInt();
|
||||
}
|
||||
|
||||
|
||||
if(request->hasParam("invert", true)) {
|
||||
const AsyncWebParameter* param = request->getParam("invert", true);
|
||||
config.system.output.invert[outputId] = param->value().toInt();
|
||||
}
|
||||
|
||||
// only fill the type related config vars
|
||||
switch(outputType) {
|
||||
|
@ -799,11 +805,6 @@ void WebPage_system_output_add(AsyncWebServerRequest *request) {
|
|||
const AsyncWebParameter* param = request->getParam("gpio_pwm", true);
|
||||
config.system.output.gpio_pwm[outputId] = param->value().toInt();
|
||||
}
|
||||
|
||||
if(request->hasParam("invert", true)) {
|
||||
const AsyncWebParameter* param = request->getParam("invert", true);
|
||||
config.system.output.invert[outputId] = param->value().toInt();
|
||||
}
|
||||
break;
|
||||
|
||||
// I2C
|
||||
|
|
Loading…
Add table
Reference in a new issue