Commit b568cd40 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

read functions

parent f3015e63
......@@ -66,8 +66,8 @@ void setup() {
// digitalWrite(RELE_1, HIGH);
// digitalWrite(RELE_2, HIGH);
//
// pinMode(RELE_READ_1, INPUT_PULLUP);
// pinMode(RELE_READ_2, INPUT_PULLUP);
pinMode(RELE_READ_1, INPUT_PULLUP);
pinMode(RELE_READ_2, INPUT_PULLUP);
// register the receive callback
LoRa.onReceive(onReceive);
......@@ -116,6 +116,9 @@ void drawTextOLED(String text) {
String r1 = String(RELE_1, 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)
{
// received a packet
......@@ -152,17 +155,15 @@ void onReceive(int packetSize)
LoRa.receive();
}
String val = "";
if(str.indexOf("read : ") >= 0)
{
//Serial.println(str);
String val;
if(str.indexOf(r1) >= 0) //TODO manca la parte di sicurezza
if(str.indexOf(read_r1) >= 0) //TODO manca la parte di sicurezza
{
val = readRele1();
}
else if(str.indexOf(r2) >= 0)
else if(str.indexOf(read_r2) >= 0)
{
val = readRele2();
}
......@@ -182,6 +183,8 @@ void onReceive(int packetSize)
Serial.print("' with RSSI ");
Serial.print(str);
Serial.print(" ");
Serial.print(val);
Serial.print(" ");
Serial.println(LoRa.packetRssi());
}
......
......@@ -47,9 +47,28 @@ SSD1306 display(0x3c, 4, 15);
String ipAddr = "";
String lastCommand = "";
String lastReceived = "";
String signalLevel = "";
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);
Serial.begin(115200);
......@@ -101,21 +120,9 @@ void setup(void)
// Add service to MDNS-SD
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.setTextAlignment(TEXT_ALIGN_LEFT);
......@@ -123,10 +130,16 @@ void drawTextOLED(String text, String ttext) {
display.drawString(0, 0, "L.C. : " + text);
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, 40, "Giacomo Lavermicocca");
display.drawString(0, 24, tttext);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 36, "Level : " + signalLevel);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 48, "Giacomo Lavermicocca");
display.display();
}
......@@ -137,7 +150,7 @@ const long interval = 10000;
void loop(void)
{
drawTextOLED(lastCommand, ipAddr);
drawTextOLED(lastCommand, ipAddr, lastReceived, signalLevel);
// Check if a client has connected
WiFiClient client = server.available();
......@@ -236,7 +249,7 @@ void loop(void)
void onReceive(int packetSize)
{
// received a packet
Serial.println("Received packet '");
//Serial.println("Received packet '");
// read packet
String str;
for (int i = 0; i < packetSize; i++)
......@@ -246,15 +259,19 @@ void onReceive(int packetSize)
str += p;
}
if (str.indexOf("received : ") >= 0)
{
lastCommand = str;
}
// if (str.indexOf("received : ") >= 0)
// {
// lastReceived = str;
// }
lastReceived = str;
// print RSSI of packet
Serial.println("");
Serial.print("with RSSI ");
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