...
 
Commits (2)
......@@ -3,8 +3,8 @@
*/
#include <heltec.h>
byte localAddress = 0xBB; // address of this device
byte destination = 0xAA; // destination to send to
byte localAddress = 0xDD; // address of this device
byte destination = 0xDE; // destination to send to
#define RELE_1 17
#define RELE_2 21
......@@ -16,13 +16,15 @@ byte destination = 0xAA; // destination to send to
String lastCommand = "";
String signalLevel = "";
#define BAND 868E6
void setup() {
Heltec.begin(true /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, 868E6 /*LoRa RF working band*/);
Heltec.begin(true /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, BAND /*LoRa RF working band*/);
Heltec.display -> clear();
Serial.println("LoRa Sender");
LoRa.setTxPowerMax(10);
LoRa.setTxPowerMax(15);
//LoRa.enableCrc();
LoRa.setPreambleLength(4);
......@@ -47,31 +49,50 @@ void setup() {
unsigned long previousMillisLed = 0;
const long intervalLed = 60000 * 10;
unsigned long previousMillisRele = 0;
const long intervalRele = 1000 * 10;
bool isLoRaOnSenderMode = false;
bool isLedOff = true;
bool lockRequestsFor10sec = false;
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillisRele > intervalRele) {
lockRequestsFor10sec = false;
} else {
lockRequestsFor10sec = true;
Heltec.display -> clear();
Heltec.display -> drawString(0, 0, lastCommand);
Heltec.display -> display();
}
if (isLedOff) {
delay(2000);
isLedOff = false;
//Reset rele
digitalWrite(RELE_1, LOW);
digitalWrite(RELE_2, LOW);
}
if(currentMillis - previousMillisLed > intervalLed){
if (currentMillis - previousMillisLed > intervalLed) {
digitalWrite(RELE_3, LOW);
//ESP.restart();
}
if(isLoRaOnSenderMode)
if (isLoRaOnSenderMode)
{
isLoRaOnSenderMode = false;
Heltec.display -> clear();
Heltec.display -> drawString(0, 0, lastCommand);
Heltec.display -> display();
String outgoing = lastCommand;
for(int i = 0; i < 10; i++){
for (int i = 0; i < 10; i++) {
// send packet
LoRa.beginPacket();
......@@ -81,6 +102,7 @@ void loop() {
LoRa.print(outgoing); // add payload
LoRa.endPacket();
delay(2000);
}
// put the radio into receive mode
......@@ -91,6 +113,7 @@ void loop() {
String r1 = String(RELE_1, DEC);
String r2 = String(RELE_2, DEC);
String r3 = String(RELE_3, DEC);
String r0 = "0";
String read_r1 = String(RELE_READ_1, DEC);
String read_r2 = String(RELE_READ_2, DEC);
......@@ -138,64 +161,72 @@ void onReceive(int packetSize)
// received a packet
String str = incoming;
if(str.indexOf("p : ") == 0)
if (str.indexOf("p : ") == 0)
{
if(str.indexOf(r1) > 0)
if (lockRequestsFor10sec == false) {
lastCommand = str;
previousMillisRele = millis();
isLedOff = true;
if (str.indexOf(r1) > 0)
{
setRele1();
}
if(str.indexOf(r2) > 0)
if (str.indexOf(r2) > 0)
{
setRele2();
}
if(str.indexOf(r3) > 0)
if (str.indexOf(r3) > 0)
{
setRele3();
}
lastCommand = str;
isLoRaOnSenderMode = true;
if (str.indexOf(r0) > 0)
{
setRele0();
}
}
}
if(str.indexOf("r : ") == 0)
if (str.indexOf("r : ") == 0)
{
val = "";
if(str.indexOf(read_r1) > 0)
if (str.indexOf(read_r1) > 0)
{
val = readRele1();
}
else if(str.indexOf(read_r2) > 0)
else if (str.indexOf(read_r2) > 0)
{
val = readRele2();
}
isLoRaOnSenderMode = true;
lastCommand = str + " " + val;
isLoRaOnSenderMode = true;
}
}
void setRele0()
{
digitalWrite(RELE_1, HIGH);
digitalWrite(RELE_2, HIGH);
digitalWrite(RELE_3, HIGH); // LUCI LED
previousMillisLed = millis();
}
void setRele1()
{
isLedOff = true;
digitalWrite(RELE_1, HIGH);
digitalWrite(RELE_3, HIGH); // LUCI LED
delay(2000);
previousMillisLed = millis();
}
void setRele2()
{
isLedOff = true;
digitalWrite(RELE_2, HIGH);
digitalWrite(RELE_3, HIGH); // LUCI LED
delay(2000);
previousMillisLed = millis();
}
void setRele3()
{
digitalWrite(RELE_3, HIGH);
......
......@@ -10,8 +10,8 @@
const char* ssid = "Thomas";
const char* password = "viapiccardi47!!thomas";
byte localAddress = 0xAA; // address of this device
byte destination = 0xBB; // destination to send to
byte localAddress = 0xDE; // address of this device
byte destination = 0xDD; // destination to send to
// TCP server at port 80 will respond to HTTP requests
WiFiServer server(80);
......@@ -26,11 +26,11 @@ void WIFISetUp(void)
delay(1000);
WiFi.mode(WIFI_STA);
WiFi.setAutoConnect(true);
WiFi.begin("Thomas","viapiccardi47!!thomas");
WiFi.begin("Thomas", "viapiccardi47!!thomas");
delay(100);
byte count = 0;
while(WiFi.status() != WL_CONNECTED && count < 10)
while (WiFi.status() != WL_CONNECTED && count < 10)
{
count ++;
delay(500);
......@@ -39,11 +39,11 @@ void WIFISetUp(void)
}
Heltec.display -> clear();
if(WiFi.status() == WL_CONNECTED)
if (WiFi.status() == WL_CONNECTED)
{
Heltec.display -> drawString(0, 0, "Connecting...OK.");
Heltec.display -> display();
// delay(500);
// delay(500);
}
else
{
......@@ -59,14 +59,16 @@ void WIFISetUp(void)
delay(500);
}
#define BAND 868E6
void setup(void)
{
Heltec.begin(true /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, 868E6 /*LoRa RF working band*/);
Heltec.begin(true /*DisplayEnable Enable*/, true /*LoRa Enable*/, false /*Serial Enable*/, true /*LoRa use PABOOST*/, BAND /*LoRa RF working band*/);
Heltec.display -> clear();
Serial.println("LoRa Sender");
LoRa.setTxPowerMax(10);
LoRa.setTxPowerMax(15);
//LoRa.enableCrc();
LoRa.setPreambleLength(4);
......@@ -88,7 +90,7 @@ void setup(void)
String s;
unsigned long previousMillis = 0;
const long interval = 10000;
const long interval = 25000;
int val = 0;
void loop(void)
......@@ -101,7 +103,7 @@ void loop(void)
long rssi = WiFi.RSSI();
if(rssi == 0)
if (rssi == 0)
{
ESP.restart();
}
......@@ -141,7 +143,6 @@ void loop(void)
} else if (req.indexOf("/pin") >= 0) {
pinRequest(req);
lastCommandReceived = "";
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
s += req;
s += "";
......@@ -150,7 +151,6 @@ void loop(void)
} else if (req.indexOf("/brightness") >= 0) {
setBrightness(req);
lastCommandReceived = "";
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
s += req;
s += "";
......@@ -239,14 +239,6 @@ void onReceive(int packetSize)
if (incoming.indexOf("r : ") == 0) {
lastCommandReceived = incoming;
}
if (incoming.indexOf("p : ") == 0) {
lastCommandReceived = incoming;
}
if (incoming.indexOf("b : ") == 0) {
lastCommandReceived = incoming;
}
}
//----------------------------------------------------------------------------------------------
......@@ -259,6 +251,7 @@ void pinRequest(String req)
String outgoing = "p : " + req;
for (int i = 0; i < 5; i++) {
// send packet
LoRa.beginPacket();
......@@ -268,9 +261,10 @@ void pinRequest(String req)
LoRa.print(outgoing); // add payload
LoRa.endPacket();
delay(2000);
}
// put the radio into receive mode
LoRa.receive();
lastCommandReceived = outgoing;
}
void setBrightness(String req)
......@@ -279,6 +273,7 @@ void setBrightness(String req)
String outgoing = "b : " + req;
for (int i = 0; i < 5; i++) {
// send packet
LoRa.beginPacket();
......@@ -288,9 +283,10 @@ void setBrightness(String req)
LoRa.print(outgoing); // add payload
LoRa.endPacket();
delay(2000);
}
// put the radio into receive mode
LoRa.receive();
lastCommandReceived = outgoing;
}
void pinRequestRead(String req)
......@@ -299,6 +295,7 @@ void pinRequestRead(String req)
String outgoing = "r : " + req;
for (int i = 0; i < 5; i++) {
// send packet
LoRa.beginPacket();
......@@ -308,6 +305,8 @@ void pinRequestRead(String req)
LoRa.print(outgoing); // add payload
LoRa.endPacket();
delay(2000);
}
// put the radio into receive mode
LoRa.receive();
......