Commit 8f29aee4 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

GPIO relè on Sender implementation

parent 9d1b5667
......@@ -69,6 +69,9 @@ void setup(void)
//-------------------------------------
pinMode(17, OUTPUT);
digitalWrite(17, LOW); // set GPIO17 low
//Initialize serial and wait for port to open:
Serial.begin(115200);
......@@ -141,12 +144,24 @@ void drawTextOLED(String text, String ttext, String rread, String signalLevel) {
String s;
unsigned long previousMillis = 0;
unsigned long previousMillisGPIO = 0;
const long interval = 10000;
//reqInt == variabile globale per sapere qual'è l'ultimo pin GPIO settato
int reqInt = 17; // just for first run
void loop(void)
{
unsigned long currentMillis = millis();
drawTextOLED(lastCommand, ipAddr, lastReceived, signalLevel);
if(previousMillisGPIO < currentMillis)
{
//reqInt == variabile globale per sapere qual'è l'ultimo pin GPIO settato
digitalWrite(reqInt, LOW); // set GPIO17 low
}
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
......@@ -172,7 +187,7 @@ void loop(void)
client.flush();
unsigned long currentMillis = millis();
currentMillis = millis();
if (req == "/")
{
......@@ -212,6 +227,15 @@ void loop(void)
s += lastCommand;
s += "";
}
} else if (req.indexOf('/gpio') > 0) {
//OK send s to browser
pinGPIO(req);
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
s += req;
s += "";
previousMillisGPIO = currentMillis + 2000;
} else {
s = "HTTP/1.1 404 Not Found\r\n\r\n";
// Serial.println("Sending 404");
......@@ -289,6 +313,15 @@ void pinRequestRead(String req)
LoRa.receive();
}
void pinGPIO(String req)
{
req = req.substring(req.lastIndexOf('/') + 1);
reqInt = req.toInt();
lastCommand = "gpio : " + String(reqInt);
digitalWrite(reqInt, HIGH); // set GPIO17 high
}
//----------------------------------------------------------------------------------------------
//---------------------------------------- ENCRIPTION ------------------------------------------
//----------------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment