Commit ed596fe4 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

Serial debug removed

parent b568cd40
/*
Uses interrup method check the new incoming messages, and print via serial
in 115200 baud rate.
The default interrupt pin in SX1276/8(DIO0) connected to ESP32's GPIO26
......@@ -35,7 +33,8 @@
SSD1306 display(0x3c, 4, 15);
String str;
String lastCommand = "";
String signalLevel = "";
void setup() {
//-------------------------------- DISPLAY ------------------------------
......@@ -49,23 +48,16 @@ void setup() {
display.setFont(ArialMT_Plain_10);
//------------------------------------------------------------------------
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver Callback");
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);
}
pinMode(RELE_1, OUTPUT);
pinMode(RELE_2, OUTPUT);
//
// digitalWrite(RELE_1, HIGH);
// digitalWrite(RELE_2, HIGH);
//
pinMode(RELE_READ_1, INPUT_PULLUP);
pinMode(RELE_READ_2, INPUT_PULLUP);
......@@ -86,16 +78,12 @@ void loop() {
//Reset rele
digitalWrite(RELE_1, HIGH);
digitalWrite(RELE_2, HIGH);
//Serial.println("IN OFF...");
}
else
{
//Serial.println("IN ON...");
//digitalWrite(RELE_1, LOW);
//digitalWrite(RELE_2, LOW);
}
drawTextOLED(str);
display.display();
drawTextOLED(lastCommand);
}
void drawTextOLED(String text) {
......@@ -106,11 +94,12 @@ void drawTextOLED(String text) {
display.drawString(0, 0, text);
display.setFont(ArialMT_Plain_10);
String rssi = "RSSI " + String(LoRa.packetRssi(), DEC);
display.drawString(0, 20, rssi);
display.drawString(0, 20, signalLevel);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 40, "Giacomo Lavermicocca");
display.display();
}
String r1 = String(RELE_1, DEC);
......@@ -122,33 +111,28 @@ String read_r2 = String(RELE_READ_2, DEC);
void onReceive(int packetSize)
{
// received a packet
Serial.print("Received packet '");
// read packet
str = "L.C. : ";
String str = "";
for (int i = 0; i < packetSize; i++)
{
char p = (char)LoRa.read();
Serial.print(p);
str += p;
}
//delay(1000);
Serial.println(str);
lastCommand = str;
if(str.indexOf("pin : ") >= 0)
if(lastCommand.indexOf("pin : ") >= 0)
{
if(str.indexOf(r1) >= 0) //TODO manca la parte di sicurezza
if(lastCommand.indexOf(r1) >= 0) //TODO manca la parte di sicurezza
{
setRele1();
}
if(str.indexOf(r2) >= 0)
if(lastCommand.indexOf(r2) >= 0)
{
setRele2();
}
LoRa.beginPacket();
LoRa.print("received : ");
LoRa.print(str);
LoRa.print(lastCommand);
LoRa.endPacket();
// put the radio into receive mode
......@@ -157,21 +141,20 @@ void onReceive(int packetSize)
String val = "";
if(str.indexOf("read : ") >= 0)
if(lastCommand.indexOf("read : ") >= 0)
{
if(str.indexOf(read_r1) >= 0) //TODO manca la parte di sicurezza
if(lastCommand.indexOf(read_r1) >= 0) //TODO manca la parte di sicurezza
{
val = readRele1();
}
else if(str.indexOf(read_r2) >= 0)
else if(lastCommand.indexOf(read_r2) >= 0)
{
val = readRele2();
}
LoRa.beginPacket();
LoRa.print("received : ");
LoRa.print(str);
LoRa.print(" read ");
LoRa.print(lastCommand);
LoRa.print(" ");
LoRa.print(val);
LoRa.endPacket();
......@@ -179,25 +162,17 @@ void onReceive(int packetSize)
LoRa.receive();
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.print(str);
Serial.print(" ");
Serial.print(val);
Serial.print(" ");
Serial.println(LoRa.packetRssi());
signalLevel = String(LoRa.packetRssi(), DEC);
}
void setRele1()
{
Serial.println("RELE_1");
digitalWrite(RELE_1, LOW);
previousMillis = millis();
}
void setRele2()
{
Serial.println("RELE_2");
digitalWrite(RELE_2, LOW);
previousMillis = millis();
}
......
......@@ -64,21 +64,19 @@ void setup(void)
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
drawTextOLED("DISPLAY OK!", "", "", "");
drawTextOLED("DISPLAY OK!", "NO ADDR", "NO COMMAND", "NO LEVEL");
//-------------------------------------
pinMode(25, OUTPUT);
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Sender");
// 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!");
//Serial.println("Starting LoRa failed!");
drawTextOLED("Starting LoRa failed!", "", "", "");
while (1);
}
......@@ -87,36 +85,34 @@ void setup(void)
// Connect to WiFi network
WiFi.begin(ssid, password);
Serial.println("");
String progress = ".";
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
drawTextOLED("DISPLAY OK!", progress, "NO COMMAND", "NO LEVEL");
progress += ".";
if(progress.length() > 30)
{
ESP.restart();
}
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
ipAddr = WiFi.localIP().toString();
Serial.println(ipAddr);
// Set up mDNS responder:
// - first argument is the domain name, in this example
// the fully-qualified domain name is "esp8266.local"
// - second argument is the IP address to advertise
// we send our IP address on the WiFi network
if (!MDNS.begin("esp32")) {
Serial.println("Error setting up MDNS responder!");
drawTextOLED("DISPLAY OK!", "Error setting up MDNS responder!", "NO COMMAND", "NO LEVEL");
while (1) {
delay(1000);
}
}
Serial.println("mDNS responder started");
// Start TCP (HTTP) server
server.begin();
Serial.println("TCP server started");
// Add service to MDNS-SD
MDNS.addService("http", "tcp", 80);
......@@ -157,8 +153,6 @@ void loop(void)
if (!client) {
return;
}
Serial.println("");
Serial.println("New client");
// Wait for data from client to become available
while (client.connected() && !client.available()) {
......@@ -173,16 +167,16 @@ 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);
//Serial.print("Invalid request: ");
//Serial.println(req);
return;
}
req = req.substring(addr_start + 1, addr_end);
Serial.print("Request: ");
Serial.println(req);
// Serial.print("Request: ");
// Serial.println(req);
client.flush();
Serial.println("Sending 200");
// Serial.println("Sending 200");
unsigned long currentMillis = millis();
......@@ -220,18 +214,18 @@ void loop(void)
s += "Timeout command";
s += "</html>\r\n\r\n";
} else {
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Last read of receive : ";
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>L.C. : ";
s += lastCommand;
s += "</html>\r\n\r\n";
}
} else {
s = "HTTP/1.1 404 Not Found\r\n\r\n";
Serial.println("Sending 404");
// Serial.println("Sending 404");
}
client.print(s);
Serial.println("Done with client");
// Serial.println("Done with client");
}
//----------------------------------------------------------------------------------------------
......@@ -249,29 +243,28 @@ void loop(void)
void onReceive(int packetSize)
{
// received a packet
//Serial.println("Received packet '");
// read packet
String str;
for (int i = 0; i < packetSize; i++)
{
char p = (char)LoRa.read();
Serial.print(p);
// Serial.print(p);
str += p;
}
// if (str.indexOf("received : ") >= 0)
// {
// lastReceived = str;
// }
if (str.indexOf("read : ") >= 0)
{
lastReceived = str;
}
lastReceived = str;
lastCommand = str;
// print RSSI of packet
Serial.println("");
Serial.print("with RSSI ");
Serial.println(LoRa.packetRssi());
// Serial.println("");
// Serial.print("with RSSI ");
// Serial.println(LoRa.packetRssi());
signalLevel = LoRa.packetRssi();
signalLevel = String(LoRa.packetRssi(), DEC);
}
//----------------------------------------------------------------------------------------------
......@@ -283,7 +276,7 @@ void pinRequest(String req)
Serial.println("pinRequest...");
req = req.substring(req.lastIndexOf('/') + 1);
int reqInt = req.toInt();
Serial.println(reqInt);
// Serial.println(reqInt);
// send packet
LoRa.beginPacket();
LoRa.print("pin : ");
......@@ -296,10 +289,10 @@ void pinRequest(String req)
void pinRequestRead(String req)
{
Serial.println("pinRequestRead...");
// Serial.println("pinRequestRead...");
req = req.substring(req.lastIndexOf('/') + 1);
int reqInt = req.toInt();
Serial.println(reqInt);
// 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