Commit 4cff0c9a authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

Commit di backup

parent ed596fe4
......@@ -94,7 +94,7 @@ void drawTextOLED(String text) {
display.drawString(0, 0, text);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 20, signalLevel);
display.drawString(0, 20, "Level : " + signalLevel);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 40, "Giacomo Lavermicocca");
......@@ -120,19 +120,19 @@ void onReceive(int packetSize)
lastCommand = str;
if(lastCommand.indexOf("pin : ") >= 0)
{
if(lastCommand.indexOf(r1) >= 0) //TODO manca la parte di sicurezza
if(str.indexOf("pin : ") >= 0)
{
if(str.indexOf(r1) >= 0) //TODO manca la parte di sicurezza
{
setRele1();
}
if(lastCommand.indexOf(r2) >= 0)
if(str.indexOf(r2) >= 0)
{
setRele2();
}
LoRa.beginPacket();
LoRa.print(lastCommand);
LoRa.print(str);
LoRa.endPacket();
// put the radio into receive mode
......@@ -141,19 +141,19 @@ void onReceive(int packetSize)
String val = "";
if(lastCommand.indexOf("read : ") >= 0)
if(str.indexOf("read : ") >= 0)
{
if(lastCommand.indexOf(read_r1) >= 0) //TODO manca la parte di sicurezza
if(str.indexOf(read_r1) >= 0) //TODO manca la parte di sicurezza
{
val = readRele1();
}
else if(lastCommand.indexOf(read_r2) >= 0)
else if(str.indexOf(read_r2) >= 0)
{
val = readRele2();
}
LoRa.beginPacket();
LoRa.print(lastCommand);
LoRa.print(str);
LoRa.print(" ");
LoRa.print(val);
LoRa.endPacket();
......
......@@ -68,14 +68,9 @@ void setup(void)
//-------------------------------------
// Serial.begin(115200);
// while (!Serial);
// Serial.println("LoRa Sender");
SPI.begin(SCK, MISO, MOSI, SS);
LoRa.setPins(SS, RST, DI0);
if (!LoRa.begin(BAND, PABOOST)) {
//Serial.println("Starting LoRa failed!");
drawTextOLED("Starting LoRa failed!", "", "", "");
while (1);
}
......@@ -118,18 +113,18 @@ void setup(void)
MDNS.addService("http", "tcp", 80);
}
void drawTextOLED(String text, String ttext, String tttext, String signalLevel) {
void drawTextOLED(String text, String ttext, String rread, String signalLevel) {
display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "L.C. : " + text);
display.drawString(0, 0, "IP addr : " + ttext);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 12, "IP addr : " + ttext);
display.drawString(0, 12, "L.C. : " + text);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 24, tttext);
display.drawString(0, 24, "L.R. : " + rread);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 36, "Level : " + signalLevel);
......@@ -167,42 +162,36 @@ void loop(void)
int addr_start = req.indexOf(' ');
int addr_end = req.indexOf(' ', addr_start + 1);
if (addr_start == -1 || addr_end == -1) {
//Serial.print("Invalid request: ");
//Serial.println(req);
return;
}
req = req.substring(addr_start + 1, addr_end);
// Serial.print("Request: ");
// Serial.println(req);
client.flush();
// Serial.println("Sending 200");
unsigned long currentMillis = millis();
if (req == "/")
{
IPAddress ip = WiFi.localIP();
String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP32 at ";
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\nHello from ESP32 at ";
s += ipStr;
s += "</html>\r\n\r\n";
s += "";
} else if (req.indexOf('/pin') > 0) {
pinRequest(req);
lastCommand = "";
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP32 at pin : ";
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
s += req;
s += "</html>\r\n\r\n";
s += "";
previousMillis = currentMillis;
} else if (req.indexOf('/read') > 0) {
pinRequestRead(req);
//lastCommand = req;
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP32 at pin read : ";
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
s += req;
s += "</html>\r\n\r\n";
s += "";
previousMillis = currentMillis;
......@@ -210,13 +199,13 @@ void loop(void)
//OK send s to browser
if (currentMillis - previousMillis >= interval) {
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>";
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
s += "Timeout command";
s += "</html>\r\n\r\n";
s += "";
} else {
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>L.C. : ";
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\nL.C. : ";
s += lastCommand;
s += "</html>\r\n\r\n";
s += "";
}
} else {
s = "HTTP/1.1 404 Not Found\r\n\r\n";
......@@ -252,17 +241,12 @@ void onReceive(int packetSize)
str += p;
}
if (str.indexOf("read : ") >= 0)
{
if (str.indexOf("read : ") >= 0) {
lastReceived = str;
} else {
}
lastCommand = str;
// print RSSI of packet
// Serial.println("");
// Serial.print("with RSSI ");
// Serial.println(LoRa.packetRssi());
lastCommand = str;
signalLevel = String(LoRa.packetRssi(), DEC);
}
......@@ -273,10 +257,8 @@ void onReceive(int packetSize)
void pinRequest(String req)
{
Serial.println("pinRequest...");
req = req.substring(req.lastIndexOf('/') + 1);
int reqInt = req.toInt();
// Serial.println(reqInt);
// send packet
LoRa.beginPacket();
LoRa.print("pin : ");
......@@ -289,10 +271,8 @@ void pinRequest(String req)
void pinRequestRead(String req)
{
// Serial.println("pinRequestRead...");
req = req.substring(req.lastIndexOf('/') + 1);
int reqInt = req.toInt();
// Serial.println(reqInt);
// send packet
LoRa.beginPacket();
LoRa.print("read : ");
......
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