diff --git a/fakeStation/fakeStation.ino b/fakeStation/fakeStation.ino index 54f1e4b..705a559 100644 --- a/fakeStation/fakeStation.ino +++ b/fakeStation/fakeStation.ino @@ -1,7 +1,5 @@ - #include - -#define Serial SerialUSB +//#include uint16_t temp ; uint16_t hum ; @@ -11,9 +9,9 @@ uint16_t IDMESSAGE; #define DelaiEntreMessages 1 // en minutes. Pour 140 messages par jour mettre 11 minutes (10,28 si c'est possible) - void setup() { + //Wire.begin(); Serial.begin(9600); Serial.println("LoRa Sender"); @@ -25,7 +23,9 @@ void setup() delay(2000); Serial.println("RaLo OK"); } - IDSTATION = 1; // Lecture de l'id + IDSTATION = 1; // Lecture de l'id de la station écrit dans l'EEPROM + //IDMESSAGE = EEPROM.read(4)*256+EEPROM.read(5); // relecture du prochain timestamp à utiliser + //IDMESSAGE = 456; } void loop() { @@ -47,9 +47,7 @@ void loop() { hum = LireHumidite(); pluie = LirePluie(); delay(1000); - LoRa.beginPacket(); - LoRa.print("0107770002004000C8"); - LoRa.endPacket(); + RadioEnvoyer(IDSTATION, IDMESSAGE, temp, hum, pluie); delay(1000); } } diff --git a/fakestation/DHT12.cpp b/fakestation/DHT12.cpp new file mode 100644 index 0000000..05e9742 --- /dev/null +++ b/fakestation/DHT12.cpp @@ -0,0 +1,67 @@ +/* + DHT12.cpp - Library for DHT12 sensor. + v0.0.1 Beta + Created by Bobadas, July 30,2016. + Released into the public domain. +*/ +#include "Arduino.h" +#include "Wire.h" +#include "DHT12.h" + +DHT12::DHT12(byte scale,byte id) +{ + if (id==0 || id>126) _id=0x5c; + else _id=id; + if (scale==0 || scale>3) _scale=CELSIUS; + else _scale=scale; +} + +byte DHT12::read() +{ + + Wire.beginTransmission(_id); + Wire.write(0); + if (Wire.endTransmission()!=0) return 1; + Wire.requestFrom(_id, 5); + for (int i=0;i<5;i++) { + datos[i]=Wire.read(); + }; + delay(50); + if (Wire.available()!=0) return 2; + if (datos[4]!=(datos[0]+datos[1]+datos[2]+datos[3])) return 3; + return 0; +} + +float DHT12::readTemperature(byte scale) +{ + float resultado=0; + byte error=read(); + +//Serial.println(error); + + + if (error!=0) return (float)error/100; + if (scale==0) scale=_scale; + switch(scale) { + case CELSIUS: + resultado=(datos[2]+(float)datos[3]/10); + break; + case FAHRENHEIT: + resultado=((datos[2]+(float)datos[3]/10)*1.8+32); + break; + case KELVIN: + resultado=(datos[2]+(float)datos[3]/10)+273.15; + break; + }; + return resultado; +} + +float DHT12::readHumidity() +{ + float resultado; + byte error=read(); + if (error!=0) return (float)error/100; + resultado=(datos[0]+(float)datos[1]/10); + return resultado; +} + diff --git a/fakestation/DHT12.h b/fakestation/DHT12.h new file mode 100644 index 0000000..78f5332 --- /dev/null +++ b/fakestation/DHT12.h @@ -0,0 +1,29 @@ +/* + DHT12.h - Library for DHT12 sensor. + v0.0.1 Beta + Created by Bobadas, July 30,2016. + Released into the public domain. +*/ +#ifndef DHT12_h +#define DHT12_h +#include "Arduino.h" +#include "Wire.h" + +#define CELSIUS 1 +#define KELVIN 2 +#define FAHRENHEIT 3 + +class DHT12 +{ + public: + DHT12(byte scale = 0, byte id = 0); + float readTemperature(byte scale = 0); + float readHumidity(); + private: + byte read(); + byte datos[5]; + byte _id; + byte _scale; +}; + +#endif diff --git a/fakestation/Humidite.ino b/fakestation/Humidite.ino index 5d7b1d4..886c6a5 100644 --- a/fakestation/Humidite.ino +++ b/fakestation/Humidite.ino @@ -1,6 +1,7 @@ // renvoie le taux d'humidité en % du DHT12 uint16_t LireHumidite() { - float H = random(0,100); + //float H = dht12.readHumidity(); //lecture du taux d'humidité + float H = random(0,100); //lecture du taux d'humidité return (uint16_t)H; // 0% à 100% } diff --git a/fakestation/Temperature.ino b/fakestation/Temperature.ino index f3ecfaf..28e093c 100644 --- a/fakestation/Temperature.ino +++ b/fakestation/Temperature.ino @@ -2,7 +2,8 @@ // DHT12 va de -25 à 75° avec resolution de 0,1° // on renvoie la (Température+40)*10 uint16_t LireTemperature() { - float T = random(0,35); + //float T = dht12.readTemperature(); //lecture de la température + float T = random(5,40); //lecture de la température return (uint16_t)((T + 40.0) * 10.0); // renvoie 150 -> -25°C et 1050 -> 75°C } diff --git a/gateway/gateway.ino b/gateway/gateway.ino index 64192cd..d2df829 100644 --- a/gateway/gateway.ino +++ b/gateway/gateway.ino @@ -38,7 +38,7 @@ void setup(){ //Ethernet.begin(mac, ip); // initialize Ethernet shield using the set mac adress and set IP Ethernet.begin(mac); // initialize Ethernet shield uding the set mac and DHCP for the IP - server.begin(); // initialize WebServer part of the librairy + Server.begin(); // initialize WebServer part of the librairy Serial.print("server is at "); // display on serial the IP you can find the webpage Serial.println(Ethernet.localIP()); }