Sender with LoRa
unknown
c_cpp
a year ago
2.4 kB
5
Indexable
Never
#include <LoRa.h> #include <SPI.h> #include <DHT.h> #define DHT1 4 // Digital pin connected to the DHT1 sensor #define DHTTYPE DHT11 // DHT 11 #define ObjectID 1654 #define Relay1 27 //For Vane_1 & Dht_1 #define Relay2 26 //For Vane_2 & Dht_2 #define Relay3 25 //For Vane_3 & Dht_3 #define Relay4 33 //For Pompe water #define ss 5 #define rst 14 #define dio0 2 int SensorPin = A0 ; DHT dht1(DHT1, DHTTYPE); bool Relay_1 = false , Relay_2 = false, Relay_3 = false ,Relay_4 = false ; typedef struct __attribute__((__packed__)) { uint8_t id; float temp1; float hum; } Donnee; void setup() { Serial.begin(115200); pinMode(Relay1,OUTPUT); pinMode(Relay2,OUTPUT); pinMode(Relay3,OUTPUT); pinMode(Relay4,OUTPUT); digitalWrite(Relay1,LOW) ; digitalWrite(Relay2,LOW) ; digitalWrite(Relay3,LOW) ; digitalWrite(Relay4,LOW) ; dht1.begin(); while (!Serial); Serial.println("LoRa Sender") ; LoRa.setPins(ss, rst, dio0); while (!LoRa.begin(866E6)) { Serial.println("."); delay(500); } LoRa.setSyncWord(0xF3); Serial.println("LoRa Initializing OK!"); } void loop() { Donnee donnee; donnee.temp1 = dht1.readTemperature(); donnee.hum = dht1.readHumidity(); donnee.id = ObjectID; delay(1000); Serial.print("L'identifiant est: "); Serial.println(donnee.id); Serial.print("Temperature1: "); Serial.print(donnee.temp1); Serial.print( "°C"); Serial.print(" | Humidité1: "); Serial.print(donnee.hum); Serial.println("%"); Serial.println("-----------------------------------"); if (donnee.hum < 40 ){ digitalWrite(Relay1,HIGH); Relay_1 = true; } else { digitalWrite(Relay1,LOW); Relay_1 = false; } if (donnee.hum < 40){ digitalWrite(Relay2,HIGH); Relay_2 = true; } else { digitalWrite(Relay2,LOW); Relay_2 = false; } if (donnee.hum < 40){ digitalWrite(Relay3,HIGH); Relay_3 = true; } else { digitalWrite(Relay3,LOW); Relay_3 = false; } if (Relay_1 || Relay_2 || Relay_3 ){ digitalWrite(Relay4,HIGH); } else { digitalWrite(Relay4,LOW); } delay(500); LoRa.beginPacket(); Serial.println("data sending"); LoRa.write((uint8_t *) &donnee, sizeof(Donnee)); Serial.println("data sent"); LoRa.endPacket(); }