Commit b568cd40 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

read functions

parent f3015e63
...@@ -66,8 +66,8 @@ void setup() { ...@@ -66,8 +66,8 @@ void setup() {
// digitalWrite(RELE_1, HIGH); // digitalWrite(RELE_1, HIGH);
// digitalWrite(RELE_2, HIGH); // digitalWrite(RELE_2, HIGH);
// //
// pinMode(RELE_READ_1, INPUT_PULLUP); pinMode(RELE_READ_1, INPUT_PULLUP);
// pinMode(RELE_READ_2, INPUT_PULLUP); pinMode(RELE_READ_2, INPUT_PULLUP);
// register the receive callback // register the receive callback
LoRa.onReceive(onReceive); LoRa.onReceive(onReceive);
...@@ -116,6 +116,9 @@ void drawTextOLED(String text) { ...@@ -116,6 +116,9 @@ void drawTextOLED(String text) {
String r1 = String(RELE_1, DEC); String r1 = String(RELE_1, DEC);
String r2 = String(RELE_2, DEC); String r2 = String(RELE_2, DEC);
String read_r1 = String(RELE_READ_1, DEC);
String read_r2 = String(RELE_READ_2, DEC);
void onReceive(int packetSize) void onReceive(int packetSize)
{ {
// received a packet // received a packet
...@@ -151,18 +154,16 @@ void onReceive(int packetSize) ...@@ -151,18 +154,16 @@ void onReceive(int packetSize)
// put the radio into receive mode // put the radio into receive mode
LoRa.receive(); LoRa.receive();
} }
String val = "";
if(str.indexOf("read : ") >= 0) if(str.indexOf("read : ") >= 0)
{ {
//Serial.println(str); if(str.indexOf(read_r1) >= 0) //TODO manca la parte di sicurezza
String val;
if(str.indexOf(r1) >= 0) //TODO manca la parte di sicurezza
{ {
val = readRele1(); val = readRele1();
} }
else if(str.indexOf(r2) >= 0) else if(str.indexOf(read_r2) >= 0)
{ {
val = readRele2(); val = readRele2();
} }
...@@ -182,6 +183,8 @@ void onReceive(int packetSize) ...@@ -182,6 +183,8 @@ void onReceive(int packetSize)
Serial.print("' with RSSI "); Serial.print("' with RSSI ");
Serial.print(str); Serial.print(str);
Serial.print(" "); Serial.print(" ");
Serial.print(val);
Serial.print(" ");
Serial.println(LoRa.packetRssi()); Serial.println(LoRa.packetRssi());
} }
......
...@@ -47,9 +47,28 @@ SSD1306 display(0x3c, 4, 15); ...@@ -47,9 +47,28 @@ SSD1306 display(0x3c, 4, 15);
String ipAddr = ""; String ipAddr = "";
String lastCommand = ""; String lastCommand = "";
String lastReceived = "";
String signalLevel = "";
void setup(void) void setup(void)
{ {
//-------- DISPLAY INIT --------------
pinMode(16, OUTPUT);
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
delay(50);
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high
// Initialising the UI will init the display too.
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
drawTextOLED("DISPLAY OK!", "", "", "");
//-------------------------------------
pinMode(25, OUTPUT); pinMode(25, OUTPUT);
Serial.begin(115200); Serial.begin(115200);
...@@ -101,21 +120,9 @@ void setup(void) ...@@ -101,21 +120,9 @@ void setup(void)
// Add service to MDNS-SD // Add service to MDNS-SD
MDNS.addService("http", "tcp", 80); MDNS.addService("http", "tcp", 80);
//-------- DISPLAY INIT --------------
pinMode(16, OUTPUT);
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
delay(50);
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high
// Initialising the UI will init the display too.
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
} }
void drawTextOLED(String text, String ttext) { void drawTextOLED(String text, String ttext, String tttext, String signalLevel) {
display.clear(); display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT); display.setTextAlignment(TEXT_ALIGN_LEFT);
...@@ -123,10 +130,16 @@ void drawTextOLED(String text, String ttext) { ...@@ -123,10 +130,16 @@ void drawTextOLED(String text, String ttext) {
display.drawString(0, 0, "L.C. : " + text); display.drawString(0, 0, "L.C. : " + text);
display.setFont(ArialMT_Plain_10); display.setFont(ArialMT_Plain_10);
display.drawString(0, 20, "IP addr : " + ttext); display.drawString(0, 12, "IP addr : " + ttext);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 24, tttext);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 36, "Level : " + signalLevel);
display.setFont(ArialMT_Plain_10); display.setFont(ArialMT_Plain_10);
display.drawString(0, 40, "Giacomo Lavermicocca"); display.drawString(0, 48, "Giacomo Lavermicocca");
display.display(); display.display();
} }
...@@ -137,7 +150,7 @@ const long interval = 10000; ...@@ -137,7 +150,7 @@ const long interval = 10000;
void loop(void) void loop(void)
{ {
drawTextOLED(lastCommand, ipAddr); drawTextOLED(lastCommand, ipAddr, lastReceived, signalLevel);
// Check if a client has connected // Check if a client has connected
WiFiClient client = server.available(); WiFiClient client = server.available();
...@@ -236,7 +249,7 @@ void loop(void) ...@@ -236,7 +249,7 @@ void loop(void)
void onReceive(int packetSize) void onReceive(int packetSize)
{ {
// received a packet // received a packet
Serial.println("Received packet '"); //Serial.println("Received packet '");
// read packet // read packet
String str; String str;
for (int i = 0; i < packetSize; i++) for (int i = 0; i < packetSize; i++)
...@@ -246,15 +259,19 @@ void onReceive(int packetSize) ...@@ -246,15 +259,19 @@ void onReceive(int packetSize)
str += p; str += p;
} }
if (str.indexOf("received : ") >= 0) // if (str.indexOf("received : ") >= 0)
{ // {
lastCommand = str; // lastReceived = str;
} // }
lastReceived = str;
// print RSSI of packet // print RSSI of packet
Serial.println(""); Serial.println("");
Serial.print("with RSSI "); Serial.print("with RSSI ");
Serial.println(LoRa.packetRssi()); Serial.println(LoRa.packetRssi());
signalLevel = LoRa.packetRssi();
} }
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
......
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