added old fake station

jd-update
Flavien Haas 6 years ago
parent 820f31909c
commit 13f86b8e20

@ -1,55 +1,53 @@
#include <SPI.h>
#include <LoRa.h>
#define Serial SerialUSB
typedef struct paquet_LoRa { // frame structure
uint16_t ID = 1025; // ID
uint16_t TS = 0; // TimeStamp
uint16_t DT = 0; // Data Type
uint16_t D1 = 0; // DATA 1
uint16_t D2 = 0; // DATA 2
uint16_t D3 = 0; // DATA 3
} trame;
uint16_t temp ;
uint16_t hum ;
uint16_t pluie ;
uint16_t IDSTATION;
uint16_t IDMESSAGE;
trame message;
#define DelaiEntreMessages 1 // en minutes. Pour 140 messages par jour mettre 11 minutes (10,28 si c'est possible)
void setup(){
void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("fakeLoRastation");
// LoRa.setSPIFrequency(4E6); //défaut 8MHz trop rapide pour l'analyseur
if( !LoRa.begin(868E6) ){
Serial.print("Echec de l'initialisation LoRa !\n");
while(true);
Serial.println("LoRa Sender");
if (!LoRa.begin(868E6)) { // Démarrage du LoRa avec une fréquence de 868MHz, si il n'y a pas de retour
Serial.println("Erreur du demarrage du LoRa!"); // on écrit un message d'erreur
while (true);
}
else {
delay(2000);
Serial.println("RaLo OK");
}
}//setup()
IDSTATION = 1; // Lecture de l'id
}
void loop() {
int c=0;
message.D1=random(0,65535);
message.D2=random(0,65535);
message.D3=random(0,65535);
String strID = String(message.ID);//0x00
String strTS = String(message.TS);//0x0000
String strDT = String(message.DT);//0x0000
String strD1 = String(message.D1);//0x0000
String strD2 = String(message.D3);//0x0000
String strD3 = String(message.D3);//0x0000
for(c=0;c<3;c++){
LoRa.beginPacket(false);
LoRa.write( (uint8_t*)&message, sizeof(message));
Serial.println("\nPacquet envoyé: ");
Serial.println("ID Passerelle et station envoyés : "+strID);
Serial.println("Timestamp envoyée: "+strTS);
Serial.println("Type de données envoyé: "+strDT);
Serial.println("Champ de données 1 envoyé: "+strD1);
Serial.println("Champ de données 2 envoyé: "+strD2);
Serial.println("Champ de données 3 envoyé: "+strD3);
LoRa.endPacket();
delay(1000);
}//findufor
message.TS = message.TS + 1;
}//loop()
static uint32_t prochainEnvoie = millis() + 0; // permet d'envoyer tout de suite
/* static long prochainCrLf = 0;
if ( ++prochainCrLf > 80 )
{
prochainCrLf = 0;
}
*/
if ( millis() > prochainEnvoie ) {
prochainEnvoie = millis() + ((uint32_t)DelaiEntreMessages * (uint32_t)60 * (uint32_t)1000); // prochain envoie dans dix minutes
Serial.print("\n\rEn procedure de travail a "); Serial.print( millis()); Serial.print(" next a "); Serial.println(prochainEnvoie);
delay(200);
temp = LireTemperature();
hum = LireHumidite();
pluie = LirePluie();
delay(1000);
RadioEnvoyer(IDSTATION, IDMESSAGE, temp, hum, pluie);
delay(1000);
}
}

@ -0,0 +1,59 @@
#include <SPI.h>
#include <LoRa.h>
#define Serial SerialUSB
typedef struct paquet_LoRa { // frame structure
uint16_t ID = 1025; // ID
uint16_t TS = 0; // TimeStamp
uint16_t DT = 0; // Data Type
uint16_t D1 = 0; // DATA 1
uint16_t D2 = 0; // DATA 2
uint16_t D3 = 0; // DATA 3
} trame;
trame message;
void setup(){
Serial.begin(9600);
while (!Serial);
Serial.println("fakeLoRastation");
if( !LoRa.begin(868E6) ){
Serial.print("Echec de l'initialisation LoRa !\n");
while(true);
}
}//setup()
void loop() {
int c=0;
message.D1=random(0,65535);
message.D2=random(0,65535);
message.D3=random(0,65535);
String strID = String(message.ID);//0x00
String strTS = String(message.TS);//0x0000
String strDT = String(message.DT);//0x0000
String strD1 = String(message.D1);//0x0000
String strD2 = String(message.D3);//0x0000
String strD3 = String(message.D3);//0x0000
for(c=0;c<3;c++){
LoRa.beginPacket(false);
LoRa.write( (uint8_t*)&message, sizeof(message));
LoRa.endPacket();
Serial.println("\nPacquet envoyé: ");
Serial.println("ID Passerelle et station envoyés : "+strID);
Serial.println("Timestamp envoyée: "+strTS);
Serial.println("Type de données envoyé: "+strDT);
Serial.println("Champ de données 1 envoyé: "+strD1);
Serial.println("Champ de données 2 envoyé: "+strD2);
Serial.println("Champ de données 3 envoyé: "+strD3);
delay(1000);
}//findufor
message.TS = message.TS + 1; //timestamp
delay(3000);
}//loop()

@ -0,0 +1,6 @@
// renvoie le taux d'humidité en % du DHT12
uint16_t LireHumidite() {
float H = random(0,100);
return (uint16_t)H; // 0% à 100%
}

@ -0,0 +1,21 @@
// renvoie la pluviometrie
// 1 -> il pleut
// 0 -> pleut pas
uint16_t LirePluie() {
const int sensorMin = 0; // valeur capteur minimum
const int sensorMax = 1024; // valeur capteur maximum
bool range;
// lecture du capteur sur A0:
//int sensorReading = analogRead(A0);
int sensorReading = random(0,1024);
Serial.print("Humidite : ");
Serial.println(sensorReading);
// transforme la valeur renvoyée du capteur en booléen
range = map(sensorReading, sensorMin, sensorMax, 0, 1);
return range;
}

@ -0,0 +1,8 @@
// renvoie la temperature du DHT12 en 10iemes de degres celsius
// DHT12 va de -25 à 75° avec resolution de 0,1°
// on renvoie la (Température+40)*10
uint16_t LireTemperature() {
float T = random(0,100);
return (uint16_t)((T + 40.0) * 10.0); // renvoie 150 -> -25°C et 1050 -> 75°C
}

@ -0,0 +1,46 @@
// envoyer les mesures
uint16_t typeDonnee = 1; //définis le type de données envoyées
#define MSB(x) ((uint8_t)( (x) >> 8) ) // définition de l'octet de poids fort par un décalage de 8bits
#define LSB(x) ((uint8_t)( (x)&0x00FF) ) // définition de l'octet de poids faible avec un masque de bits
// idStation entre 0 et 255 (le poid fort sera imposé par la passerelle)
int RadioEnvoyer( uint16_t idStation, uint16_t idMessage, uint16_t Temperature, uint16_t Humidite, uint16_t ilpleut ) {
idMessage++;
//EEPROM.write( 4, idMessage>>8 );
//EEPROM.write( 5, idMessage&0x00FF ); // ecriture du prochain timestamp à utiliser en cas de redémarrage
Serial.print("RadioEnvoyer.idstation : "); Serial.println(idStation);
Serial.print("RadioEnvoyer.Temperature : "); Serial.println(Temperature);
Serial.print("RadioEnvoyer.Humidite : "); Serial.println(Humidite);
Serial.print("RadioEnvoyer.Il pleut ? : "); Serial.println(ilpleut);
for (int i = 0; i < 3; i++) { // on envoie le message 3 fois
LoRa.beginPacket(); //crée une en-tête automatiquement et réinitialise les registres et la taille du message
LoRa.write( MSB(idStation) ); //écrit les données de "idStation" dans le registre définis par LoRa.beginPacket et met à jour la taille du paquet
LoRa.write( LSB(idStation) );
LoRa.write( MSB(idMessage) );
LoRa.write( LSB(idMessage) );
LoRa.write( MSB(typeDonnee) );
LoRa.write( LSB(typeDonnee) );
LoRa.write( MSB(Temperature) );
LoRa.write( LSB(Temperature) );
LoRa.write( MSB(Humidite) );
LoRa.write( LSB(Humidite) );
LoRa.write( MSB(ilpleut) );
LoRa.write( LSB(ilpleut) );
LoRa.endPacket(); //envoie les données et vide le contenu des registres
delay(5000);
}
}

@ -54,12 +54,12 @@ void setup(){
void loop() {
// LoRa receiver
String strID = String(message.ID);//0x00
String strTS = String(message.TS);//0x0000
String strDT = String(message.DT);//0x0000
String strD1 = String(message.D1);//0x0000
String strD2 = String(message.D3);//0x0000
String strD3 = String(message.D3);//0x0000
String strID = String(message.ID);//0x00
String strTS = String(message.TS);//0x0000
String strDT = String(message.DT);//0x0000
String strD1 = String(message.D1);//0x0000
String strD2 = String(message.D3);//0x0000
String strD3 = String(message.D3);//0x0000
static byte tampon[LENMAX]={0}; // if the module receive a frame, it willnot be null
@ -84,28 +84,21 @@ String strD3 = String(message.D3);//0x0000
for( int i=0; i<longueurTrame; i++ ){
if( (tampon[i] < 0x20)||(tampon[i] > 0x7E) ){
Serial.print( "."); // this character isn't printable (displayable)
}else{
//Serial.print( (char)tampon[i] );
// display the frame in ASCII
//Serial.println("\nTaille du pacquet reçu en octets: "+taillepaquet);
Serial.println("ID Passerelle et station reçus : "+strID);
Serial.println("Timestamp reçue : "+strTS);
Serial.println("Type de données reçus : "+strDT);
Serial.println("Champ de données 1 reçus : "+strD1);
Serial.println("Champ de données 2 reçus : "+strD2);
Serial.println("Champ de données 3 reçus : "+strD3);
}
else{
Serial.print( (char)tampon[i] ); // display the frame in ASCII
Serial.println("\nTaille du pacquet reçu en octets: "+LENMAX);
Serial.println("ID Passerelle et station reçus : "+strID);
Serial.println("Timestamp reçue : "+strTS);
Serial.println("Type de données reçus : "+strDT);
Serial.println("Champ de données 1 reçus : "+strD1);
Serial.println("Champ de données 2 reçus : "+strD2);
Serial.println("Champ de données 3 reçus : "+strD3);
}
}
Serial.print( "\n" );
} // end of if LoRa.parsePacket
delay(10);
// Lora receiver
// WebServer
EthernetClient client = server.available(); // WebServer :listen for incoming clients

Loading…
Cancel
Save