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

Change library and harware controls added

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