Commit 8889639b authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

Change library and harware controls added

parent eefaf6ba
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
#define RST 14 // GPIO14 -- SX127x's RESET #define RST 14 // GPIO14 -- SX127x's RESET
#define DI0 26 // GPIO26 -- SX127x's IRQ(Interrupt Request) #define DI0 26 // GPIO26 -- SX127x's IRQ(Interrupt Request)
#define BAND 915E6 //you can set band here directly,e.g. 868E6,915E6 #define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
#define PABOOST true
#define RELE_1 17 #define RELE_1 17
#define RELE_2 21 #define RELE_2 21
...@@ -74,7 +73,7 @@ void setup() { ...@@ -74,7 +73,7 @@ void setup() {
LoRa.setTxPower(20,PA_OUTPUT_PA_BOOST_PIN); LoRa.setTxPower(20,PA_OUTPUT_PA_BOOST_PIN);
LoRa.setPreambleLength(8); LoRa.setPreambleLength(8);
LoRa.setPins(SS,RST,DI0); LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(BAND, PABOOST)) { if (!LoRa.begin(BAND)) {
drawTextOLED("Starting LoRa failed!"); drawTextOLED("Starting LoRa failed!");
while (1); while (1);
} }
......
...@@ -4,13 +4,8 @@ ...@@ -4,13 +4,8 @@
Http comunications with outside Http comunications with outside
*/ */
#include <WiFiClientSecure.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <SPI.h>
#include <LoRa.h> #include <LoRa.h>
#include <WiFiClientSecure.h>
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"` #include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
...@@ -30,7 +25,7 @@ WiFiServer server(80); ...@@ -30,7 +25,7 @@ WiFiServer server(80);
#define DI0 26 // GPIO26 -- SX127x's IRQ(Interrupt Request) #define DI0 26 // GPIO26 -- SX127x's IRQ(Interrupt Request)
#define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6 #define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
#define PABOOST true //#define PABOOST true
SSD1306 display(0x3c, 4, 15); SSD1306 display(0x3c, 4, 15);
...@@ -39,12 +34,14 @@ String lastCommand = ""; ...@@ -39,12 +34,14 @@ String lastCommand = "";
String lastReceived = ""; String lastReceived = "";
String signalLevel = ""; String signalLevel = "";
int val = 0;
void setup(void) void setup(void)
{ {
Serial.begin(115200); // Serial.begin(115200);
while (!Serial) { // while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only // ; // wait for serial port to connect. Needed for native USB port only
} // }
//-------- DISPLAY INIT -------------- //-------- DISPLAY INIT --------------
...@@ -58,7 +55,7 @@ void setup(void) ...@@ -58,7 +55,7 @@ void setup(void)
display.flipScreenVertically(); display.flipScreenVertically();
display.setFont(ArialMT_Plain_10); display.setFont(ArialMT_Plain_10);
drawTextOLED("DISPLAY OK!", "NO ADDR", "NO COMMAND", "NO LEVEL"); //drawTextOLED("DISPLAY OK!", "NO ADDR", "NO COMMAND", "NO LEVEL");
//------------------------------------- //-------------------------------------
...@@ -70,11 +67,13 @@ void setup(void) ...@@ -70,11 +67,13 @@ void setup(void)
LoRa.setTxPower(20,PA_OUTPUT_PA_BOOST_PIN); LoRa.setTxPower(20,PA_OUTPUT_PA_BOOST_PIN);
LoRa.setPreambleLength(8); LoRa.setPreambleLength(8);
LoRa.setPins(SS, RST, DI0); LoRa.setPins(SS, RST, DI0);
if (!LoRa.begin(BAND, PABOOST)) { if (!LoRa.begin(BAND)) {
drawTextOLED("Starting LoRa failed!", "", "", ""); //drawTextOLED("Starting LoRa failed!", "", "", "");
while (1); while (1);
} }
LoRa.noCrc();
WiFi.mode (WIFI_STA); WiFi.mode (WIFI_STA);
WiFi.setSleep(false); WiFi.setSleep(false);
...@@ -85,7 +84,7 @@ void setup(void) ...@@ -85,7 +84,7 @@ void setup(void)
// Wait for connection // Wait for connection
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(500); delay(500);
drawTextOLED("DISPLAY OK!", progress, "NO COMMAND", "NO LEVEL"); //drawTextOLED("DISPLAY OK!", progress, "NO COMMAND", "NO LEVEL");
progress += "."; progress += ".";
if(progress.length() > 30) if(progress.length() > 30)
{ {
...@@ -96,46 +95,68 @@ void setup(void) ...@@ -96,46 +95,68 @@ void setup(void)
// Start TCP (HTTP) server // Start TCP (HTTP) server
server.begin(); server.begin();
}
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, "IP addr : " + ttext);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 12, "L.C. : " + text);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 24, "L.R. : " + rread);
display.setFont(ArialMT_Plain_10); //SETUP PIN
display.drawString(0, 36, "Level : " + signalLevel); pinMode(17, INPUT); // set pin to input
digitalWrite(17, HIGH); // turn on pullup resistors
display.setFont(ArialMT_Plain_10); pinMode(21, INPUT); // set pin to input
display.drawString(0, 48, "Giacomo Lavermicocca"); digitalWrite(21, HIGH); // turn on pullup resistors
display.display();
} }
//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, "IP addr : " + ttext);
//
// display.setFont(ArialMT_Plain_10);
// display.drawString(0, 12, "L.C. : " + text);
//
// display.setFont(ArialMT_Plain_10);
// display.drawString(0, 24, "L.R. : " + rread);
//
// display.setFont(ArialMT_Plain_10);
// display.drawString(0, 36, "Level : " + signalLevel);
//
// display.setFont(ArialMT_Plain_10);
// display.drawString(0, 48, "Giacomo Lavermicocca");
//
// display.display();
//}
String s; String s;
unsigned long previousMillis = 0; unsigned long previousMillis = 0;
const long interval = 10000; const long interval = 10000;
void loop(void) void loop(void)
{ {
val = digitalRead(17);
if(val == 1){
pinRequest(String(17));
}
val = digitalRead(21);
if(val == 1){
pinRequest(String(21));
}
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
drawTextOLED(lastCommand, ipAddr, lastReceived, signalLevel);
if (currentMillis - previousMillis >= interval) {
LoRa.sleep();
}
if (WiFi.status() != WL_CONNECTED) {
ESP.restart();
}
long rssi = WiFi.RSSI(); long rssi = WiFi.RSSI();
if(rssi == 0) if(rssi == 0)
{ {
ESP.restart(); ESP.restart();
} }
//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();
...@@ -232,7 +253,6 @@ void loop(void) ...@@ -232,7 +253,6 @@ void loop(void)
void onReceive(int packetSize) void onReceive(int packetSize)
{ {
//LoRa.crc();
// received a packet // received a packet
// read packet // read packet
String str; String str;
...@@ -269,7 +289,7 @@ void pinRequest(String req) ...@@ -269,7 +289,7 @@ void pinRequest(String req)
req = req.substring(req.lastIndexOf('/') + 1); req = req.substring(req.lastIndexOf('/') + 1);
int reqInt = req.toInt(); int reqInt = req.toInt();
for(int i=0;i < 10;i++) for(int i=0;i < 30;i++)
{ {
// send packet // send packet
LoRa.beginPacket(); LoRa.beginPacket();
......
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