Components and supplies
Raspberry Pi 3 Model B
Grove - LoRa Radio 433MHz
Arduino UNO
Raspberry PI2
Grove temp and pressure sensors
Grove base shiled for Uno
Grove temp and hulidity sensors
Bonnet Lora 433 for PI
Project description
Code
The radio server
python
A python prog that receive the radio Lora message from the Arduino and send the value of the sensor to the Jeedom box via HTTP. Pycurl is used for HTTP.
1 2# Import Python System Libraries 3import time 4# Import Blinka Libraries 5import busio 6from digitalio import DigitalInOut, Direction, Pull 7import board 8# Import the SSD1306 module. 9import adafruit_ssd1306 10# Import RFM9x 11import adafruit_rfm9x 12# 13import pycurl 14from io import BytesIO 15from datetime import datetime 16 17# Create the I2C interface. 18i2c = busio.I2C(board.SCL, board.SDA) 19 20# 128x32 OLED Display 21reset_pin = DigitalInOut(board.D4) 22display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin) 23# Clear the display. 24display.fill(0) 25display.show() 26width = display.width 27height = display.height 28 29# Configure LoRa Radio 30CS = DigitalInOut(board.CE1) 31RESET = DigitalInOut(board.D25) 32spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 33rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 439.0) 34rfm9x.tx_power = 13 35rfm9x.enable_crc 36# la valeur du TO st a regler precisement ... ne pas bidouiller 37rfm9x.receive_timeout=2 38# SF=12 ==> Chips=4096 39rfm9x.spreading_factor=12 40#CR=4/8 41rfm9x.coding_rate=8 42# Power selon le destinataire 43PWR_CAVE=13 44PWR_BARO=6 45# DATAGRAMME 46SOURCE="NONE" 47NUMMES="000000" 48CDMES="CODE" 49VALMES="0000.0" 50 51def main(): 52 colMess=35 53 scroll=0 54 power=6 55 # 56 while True: 57 packet = None 58 # draw a box to clear the image 59 display.fill(0) 60 # display(texte,col,lg,1) 61 display.text('RasPi LoRa', colMess-scroll, 0, 1) 62 63 # check for packet rx 64 #print("av rec ",datetime.now().isoformat()[:19]) 65 packet = rfm9x.receive() 66 #print("ap rec ",datetime.now().isoformat()[:19]) 67 #print(datetime.now().isoformat()[:19]," - ",packet) 68 if packet is None: 69 display.show() 70 display.text('- Waiting for PKT -', colMess-scroll, 20, 1) 71 else: 72 # Display the packet text and rssi 73 display.fill(0) 74 # 75 # Grer les pb d'encodage dus aux interferences 76 try: 77 packet_text = packet.decode(encoding="utf-8", errors="replace") 78 print(datetime.now().isoformat()[:19]," - ",packet_text,flush='True') 79 # Decoupe DATAGRAMME 80 SOURCE=packet_text[0:4] 81 NUMMES=packet_text[4:10] 82 if SOURCE=="CAVE": 83 labHumi=packet_text[10:14] 84 valHumi=packet_text[18:20] 85 labTemp=packet_text[20:24] 86 valTemp=packet_text[26:30] 87 display.text(SOURCE,0,0,1) 88 display.text(labHumi,20,8,1) 89 display.text(valHumi,50,8,1) 90 display.text(labTemp,20,16,1) 91 display.text(valTemp,50,16,1) 92 msg=bytes(SOURCE+"OK guy !\ \ 93\\0","utf-8") 94 # Envoi Jeedom 95 if(valHumi.strip().isnumeric()==True): 96 envoieValeur(471,int(valHumi.strip())) 97 if(valTemp.strip().isnumeric()==True): 98 envoieValeur(472,float(valTemp.strip())/100) 99 envoieValeur(478,datetime.now().isoformat()[:19]) 100 power=PWR_CAVE 101 elif SOURCE=="BARO": 102 labPres=packet_text[10:14] 103 valPres=packet_text[16:20] 104 labTemp=packet_text[20:24] 105 valTemp=packet_text[26:30] 106 display.text(SOURCE,0,0,1) 107 display.text(labPres,20,8,1) 108 display.text(valPres,50,8,1) 109 display.text(labTemp,20,16,1) 110 display.text(valTemp,50,16,1) 111 msg=bytes(SOURCE+"OK guy !\ \ 112\\0","utf-8") 113 # Envoi Jeedom 114 if(valPres.strip().isnumeric()==True): 115 envoieValeur(476,int(valPres.strip())) 116 if(valTemp.strip().isnumeric()==True): 117 envoieValeur(477,float(valTemp.strip())/100) 118 envoieValeur(479,datetime.now().isoformat()[:19]) 119 power=PWR_BARO 120 else: 121 display.text("SOURCE INCONNUE !",0,0,1) 122 msg=bytes("SOURCE INCONNUE !\ \ 123\\0","utf-8") 124 except Exception as e: 125 print("Err : ",packet,e,sep=' - ',flush='True') 126 #print(packet) 127 packet_text = "Err encodage" 128 display.text(packet_text,0,0,1) 129 msg=bytes(SOURCE+"KO guy, pb encodage !\ \ 130\\0","utf-8") 131 # 132 time.sleep(0.1) 133 rfm9x.tx_power = power 134 rfm9x.send(msg) 135 display.text('Msg sent !', 0, 24, 1) 136 137 display.show() 138 time.sleep(5) 139 scroll=scroll+1 140 if scroll>=30: 141 scroll=0 142 143def envoieValeur(id,valeur): 144 u="" 145 status="" 146 try: 147 u='http://<an IP adress>/core/api/jeeApi.php?apikey=<the API of the jeedom>&type=virtual&id='+str(id)+'&value='+str(valeur) 148 #print(u) 149 buffer = BytesIO() 150 c = pycurl.Curl() 151 c.setopt(c.WRITEFUNCTION, buffer.write) 152 c.setopt(c.URL,u) 153 c.perform() 154 status = c.getinfo(pycurl.HTTP_CODE) 155 except Exception as e: 156 print(datetime.now().isoformat()," - Erreur lors de l envoi") 157 print("URL : ",u) 158 print("Status : ",status) 159 finally: 160 c.close() 161 162if __name__ == "__main__": 163 main() 164 165
The barometer
c_cpp
It's the code for one of the Arduino device. It's the one at home.
1 2#include <Dps310.h> 3#include <Dps422.h> 4#include <DpsClass.h> 5#include <math.h> 6 7#include <SoftwareSerial.h> 8#include <RH_RF95.h> 9 10Dps310 Dps310PressureSensor = Dps310(); 11 12// RF95 sur D6 13const int RX = 6; 14const int TX = 7; 15// Singleton instance of the radio driver 16SoftwareSerial ss(RX, TX); // RX, TX 17RH_RF95<SoftwareSerial> rf95(ss); 18// 19float pres=0, temp=0; 20float resTemp=0, resPres=0; 21uint8_t oversampling = 7; 22int ret=0; 23const int CALIB_PRESS = 7; // Calibrage du baromtre pour Paris 14 24// 25unsigned int nbcar=0, compt=0, offsetPwr=0, power=6; 26// DATUM 27// SOURCE : 4 CHAR 28// NUM MES : 6 CHAR 29// MESURE : 10 CHAR dont CD MES : 4 CHAR et Val Mes : 6 CHAR 30// Taille DATUM = SOURCE + NUM MES + N * (MESURES) = 10 + (N * 10) + \\0 31char msg[31] ; 32char SOURCE[5]="BARO"; 33char MESPRES[5]="PRES"; 34char MESTEMP[5]="TEMP"; 35 36void setup() { 37 // put your setup code here, to run once: 38 Serial.begin(9600); 39 // Pressure sensor 40 Dps310PressureSensor.begin(Wire); 41 // Radio 42 if (!rf95.init()) 43 { 44 Serial.println("init failed"); 45 while(1); 46 } 47 48 // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on 49 50 // The default transmitter power is 13dBm, using PA_BOOST. 51 // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 52 // you can set transmitter powers from 5 to 23 dBm: 53 rf95.setFrequency(439.0); 54 rf95.setModemConfig(rf95.Bw125Cr48Sf4096); 55 //Serial.print("Conf : "); Serial.println(rf95.Bw125Cr48Sf4096); 56 rf95.setTxPower(power, false); 57} 58 59void loop() { 60 // put your main code here, to run repeatedly: 61 memset(msg,'\\0',sizeof(msg)); 62 // Message de wake up car cot PI ca roupille des fois 63 nbcar = sprintf(msg,"%s","WAKE UP from BARO!"); 64 rf95.send(msg, sizeof(msg)); 65 delay(20000); // pas trop court le dlai 66 memset(msg,'\\0',sizeof(msg)); 67 // DPS310 - Temp 68 ret = Dps310PressureSensor.measureTempOnce(temp, oversampling); 69 if(ret==0){ 70 resTemp=temp; 71 Serial.print("Temp : ");Serial.println(temp); 72 }else{ 73 Serial.print("Err lect Temp : ");Serial.println(ret); 74 } 75// Pression 76 ret = Dps310PressureSensor.measurePressureOnce(pres, oversampling); 77 if(ret==0){ 78 resPres=round(pres/100)+CALIB_PRESS ; 79 Serial.print("Pres : ");Serial.println(pres); 80 }else{ 81 Serial.print("Err lect Pres : ");Serial.println(ret); 82 } 83 // 84 compt+=1; 85 // Formattage message 86 // Arduino ne prend pas en charge simplement les float dans les xprintf (%f) 87 // On passera des entiers la place 88 nbcar = sprintf(msg,"%s%6u%s%6d%s%6d",SOURCE,compt,MESPRES,int(resPres),MESTEMP,int(resTemp*100)); 89 Serial.print(nbcar);Serial.print(" - Msg : ");Serial.println(msg); 90 // ce module est client 91 // Envoi radio 92 rf95.send(msg, sizeof(msg)); 93 94 rf95.waitPacketSent(); 95 96 // Now wait for a reply 97 uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; 98 uint8_t len = sizeof(buf); 99 100 if(rf95.waitAvailableTimeout(5000)) 101 { 102 // Should be a reply message for us now 103 if(rf95.recv(buf, &len)) 104 { 105 Serial.print("Recv OK : "); Serial.println((char*)buf); 106 } 107 else 108 { 109 Serial.println("Recv Err"); 110 } 111 } 112 else 113 { 114 Serial.println("Pas de rception"); 115 } 116 117 // 118 delay(3602000); // 1 heure + 7s - 5s ci-dessus 119 //offsetPwr+=1; 120 //if(offsetPwr>=8){ 121 // offsetPwr=0; 122 //} 123 //Serial.print("Pwr : ");Serial.println(power-offsetPwr); 124 //rf95.setTxPower(power-offsetPwr, false); 125} 126
The cellar
c_cpp
This prog is for the Arduino located into the cellar, out of the home
1 2#include <ATH20.h> 3#include <math.h> 4 5#include <SoftwareSerial.h> 6#include <RH_RF95.h> 7 8ATH20 ATH; 9 10// RF95 sur D6 11const int RX = 6; 12const int TX = 7; 13// Singleton instance of the radio driver 14SoftwareSerial ss(RX, TX); // RX, TX 15RH_RF95<SoftwareSerial> rf95(ss); 16// 17float humi=0, temp=0; 18float resTemp=0, resHumi=0; 19 20// 21unsigned int nbcar=0, compt=0, power=13, offsetPwr=0, OFFSET_PWR_MAX=10; 22// DATUM 23// SOURCE : 4 CHAR 24// NUM MES : 6 CHAR 25// MESURE : 10 CHAR dont CD MES : 4 CHAR et Val Mes : 6 CHAR 26// Taille DATUM = SOURCE + NUM MES + N * (MESURES) = 10 + (N * 10) + \\0 27char msg[31] ; 28char SOURCE[5]="CAVE"; 29char MESHUMI[5]="HUMI"; 30char MESTEMP[5]="TEMP"; 31 32void setup() { 33 // put your setup code here, to run once: 34 Serial.begin(9600); 35 // Setup ATH20 36 ATH.begin(); 37 // Radio 38 if (!rf95.init()) 39 { 40 Serial.println("init failed"); 41 while(1); 42 } 43 44 // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on 45 46 // The default transmitter power is 13dBm, using PA_BOOST. 47 // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 48 // you can set transmitter powers from 5 to 23 dBm: 49 rf95.setFrequency(439.0); 50 rf95.setModemConfig(rf95.Bw125Cr48Sf4096); 51 //Serial.print("Conf : "); Serial.println(rf95.Bw125Cr48Sf4096); 52 rf95.setTxPower(power, false); 53} 54 55void loop() { 56 // put your main code here, to run repeatedly: 57 memset(msg,'\\0',sizeof(msg)); 58 // Message de wake up car cot PI ca roupille des fois 59 nbcar = sprintf(msg,"%s","WAKE UP from CAVE !"); 60 rf95.send(msg, sizeof(msg)); 61 delay(20000); // pas trop court le dlai 62 memset(msg,'\\0',sizeof(msg)); 63 // ATH20 - Temp and Humi 64 int retATH = ATH.getSensor(&humi, &temp); 65 // 66 if (retATH){ 67 resTemp=temp; resHumi=humi; 68 Serial.print("Temp : ");Serial.println(resTemp); 69 Serial.print("Humi : ");Serial.println(resHumi*100); 70 } 71 compt+=1; 72 // Formattage message 73 // Arduino ne prend pas en charge simplement les float dans les xprintf (%f) 74 // On passera des entiers la place 75// int nbcar = sprintf(msg,"%s%6u%s%6d%s%6d",SOURCE,compt,MESHUMI,int(resHumi*100),MESTEMP,int(resTemp*100)); 76 nbcar = sprintf(msg,"%s%2u%4u%s%6d%s%6d",SOURCE,power+offsetPwr,compt,MESHUMI,int(resHumi*100),MESTEMP,int(resTemp*100)); 77 Serial.print(nbcar);Serial.print(" - Msg : ");Serial.println(msg); 78 // ce module est client 79 // Envoi radio 80 rf95.send(msg, sizeof(msg)); 81 82 rf95.waitPacketSent(); 83 84 // Now wait for a reply 85 uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; 86 uint8_t len = sizeof(buf); 87 88 if(rf95.waitAvailableTimeout(5000)) 89 { 90 // Should be a reply message for us now 91 if(rf95.recv(buf, &len)) 92 { 93 Serial.print("Recv OK : "); Serial.println((char*)buf); 94 } 95 else 96 { 97 Serial.println("Recv Err"); 98 } 99 } 100 else 101 { 102 Serial.println("Pas de rception"); 103 } 104 105 // 106 delay(1796000); // 1/2 heure + 1s - 5s ci-dessus 107 // Gestion de la puissance 108 offsetPwr+=1; 109 if(offsetPwr>=OFFSET_PWR_MAX){ 110 offsetPwr=0; 111 } 112 rf95.setTxPower(power+offsetPwr, false); 113} 114
The radio server
python
A python prog that receive the radio Lora message from the Arduino and send the value of the sensor to the Jeedom box via HTTP. Pycurl is used for HTTP.
1 2# Import Python System Libraries 3import time 4# Import Blinka 5 Libraries 6import busio 7from digitalio import DigitalInOut, Direction, Pull 8import 9 board 10# Import the SSD1306 module. 11import adafruit_ssd1306 12# Import RFM9x 13import 14 adafruit_rfm9x 15# 16import pycurl 17from io import BytesIO 18from datetime 19 import datetime 20 21# Create the I2C interface. 22i2c = busio.I2C(board.SCL, 23 board.SDA) 24 25# 128x32 OLED Display 26reset_pin = DigitalInOut(board.D4) 27display 28 = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin) 29# Clear the display. 30display.fill(0) 31display.show() 32width 33 = display.width 34height = display.height 35 36# Configure LoRa Radio 37CS = 38 DigitalInOut(board.CE1) 39RESET = DigitalInOut(board.D25) 40spi = busio.SPI(board.SCK, 41 MOSI=board.MOSI, MISO=board.MISO) 42rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 43 439.0) 44rfm9x.tx_power = 13 45rfm9x.enable_crc 46# la valeur du TO st a regler 47 precisement ... ne pas bidouiller 48rfm9x.receive_timeout=2 49# SF=12 ==> Chips=4096 50rfm9x.spreading_factor=12 51#CR=4/8 52rfm9x.coding_rate=8 53# 54 Power selon le destinataire 55PWR_CAVE=13 56PWR_BARO=6 57# DATAGRAMME 58SOURCE="NONE" 59NUMMES="000000" 60CDMES="CODE" 61VALMES="0000.0" 62 63def 64 main(): 65 colMess=35 66 scroll=0 67 power=6 68 # 69 while True: 70 packet 71 = None 72 # draw a box to clear the image 73 display.fill(0) 74 # display(texte,col,lg,1) 75 76 display.text('RasPi LoRa', colMess-scroll, 0, 1) 77 78 # check for packet 79 rx 80 #print("av rec ",datetime.now().isoformat()[:19]) 81 packet = rfm9x.receive() 82 83 #print("ap rec ",datetime.now().isoformat()[:19]) 84 #print(datetime.now().isoformat()[:19]," 85 - ",packet) 86 if packet is None: 87 display.show() 88 display.text('- 89 Waiting for PKT -', colMess-scroll, 20, 1) 90 else: 91 # Display the 92 packet text and rssi 93 display.fill(0) 94 # 95 # Grer les 96 pb d'encodage dus aux interferences 97 try: 98 packet_text = packet.decode(encoding="utf-8", 99 errors="replace") 100 print(datetime.now().isoformat()[:19]," - ",packet_text,flush='True') 101 102 # Decoupe DATAGRAMME 103 SOURCE=packet_text[0:4] 104 NUMMES=packet_text[4:10] 105 106 if SOURCE=="CAVE": 107 labHumi=packet_text[10:14] 108 valHumi=packet_text[18:20] 109 110 labTemp=packet_text[20:24] 111 valTemp=packet_text[26:30] 112 113 display.text(SOURCE,0,0,1) 114 display.text(labHumi,20,8,1) 115 116 display.text(valHumi,50,8,1) 117 display.text(labTemp,20,16,1) 118 119 display.text(valTemp,50,16,1) 120 msg=bytes(SOURCE+"OK 121 guy !\ \ 122\\0","utf-8") 123 # Envoi Jeedom 124 if(valHumi.strip().isnumeric()==True): 125 126 envoieValeur(471,int(valHumi.strip())) 127 if(valTemp.strip().isnumeric()==True): 128 129 envoieValeur(472,float(valTemp.strip())/100) 130 envoieValeur(478,datetime.now().isoformat()[:19]) 131 132 power=PWR_CAVE 133 elif SOURCE=="BARO": 134 labPres=packet_text[10:14] 135 136 valPres=packet_text[16:20] 137 labTemp=packet_text[20:24] 138 139 valTemp=packet_text[26:30] 140 display.text(SOURCE,0,0,1) 141 142 display.text(labPres,20,8,1) 143 display.text(valPres,50,8,1) 144 145 display.text(labTemp,20,16,1) 146 display.text(valTemp,50,16,1) 147 148 msg=bytes(SOURCE+"OK guy !\ \ 149\\0","utf-8") 150 # 151 Envoi Jeedom 152 if(valPres.strip().isnumeric()==True): 153 envoieValeur(476,int(valPres.strip())) 154 155 if(valTemp.strip().isnumeric()==True): 156 envoieValeur(477,float(valTemp.strip())/100) 157 158 envoieValeur(479,datetime.now().isoformat()[:19]) 159 power=PWR_BARO 160 161 else: 162 display.text("SOURCE INCONNUE !",0,0,1) 163 msg=bytes("SOURCE 164 INCONNUE !\ \ 165\\0","utf-8") 166 except Exception as e: 167 print("Err 168 : ",packet,e,sep=' - ',flush='True') 169 #print(packet) 170 packet_text 171 = "Err encodage" 172 display.text(packet_text,0,0,1) 173 msg=bytes(SOURCE+"KO 174 guy, pb encodage !\ \ 175\\0","utf-8") 176 # 177 time.sleep(0.1) 178 179 rfm9x.tx_power = power 180 rfm9x.send(msg) 181 display.text('Msg 182 sent !', 0, 24, 1) 183 184 display.show() 185 time.sleep(5) 186 scroll=scroll+1 187 188 if scroll>=30: 189 scroll=0 190 191def envoieValeur(id,valeur): 192 u="" 193 194 status="" 195 try: 196 u='http://<an IP adress>/core/api/jeeApi.php?apikey=<the 197 API of the jeedom>&type=virtual&id='+str(id)+'&value='+str(valeur) 198 #print(u) 199 200 buffer = BytesIO() 201 c = pycurl.Curl() 202 c.setopt(c.WRITEFUNCTION, 203 buffer.write) 204 c.setopt(c.URL,u) 205 c.perform() 206 status = c.getinfo(pycurl.HTTP_CODE) 207 208 except Exception as e: 209 print(datetime.now().isoformat()," - Erreur lors 210 de l envoi") 211 print("URL : ",u) 212 print("Status : ",status) 213 214 finally: 215 c.close() 216 217if __name__ == "__main__": 218 main() 219 220
The barometer
c_cpp
It's the code for one of the Arduino device. It's the one at home.
1 2#include <Dps310.h> 3#include <Dps422.h> 4#include <DpsClass.h> 5#include <math.h> 6 7#include <SoftwareSerial.h> 8#include <RH_RF95.h> 9 10Dps310 Dps310PressureSensor = Dps310(); 11 12// RF95 sur D6 13const int RX = 6; 14const int TX = 7; 15// Singleton instance of the radio driver 16SoftwareSerial ss(RX, TX); // RX, TX 17RH_RF95<SoftwareSerial> rf95(ss); 18// 19float pres=0, temp=0; 20float resTemp=0, resPres=0; 21uint8_t oversampling = 7; 22int ret=0; 23const int CALIB_PRESS = 7; // Calibrage du baromtre pour Paris 14 24// 25unsigned int nbcar=0, compt=0, offsetPwr=0, power=6; 26// DATUM 27// SOURCE : 4 CHAR 28// NUM MES : 6 CHAR 29// MESURE : 10 CHAR dont CD MES : 4 CHAR et Val Mes : 6 CHAR 30// Taille DATUM = SOURCE + NUM MES + N * (MESURES) = 10 + (N * 10) + \\0 31char msg[31] ; 32char SOURCE[5]="BARO"; 33char MESPRES[5]="PRES"; 34char MESTEMP[5]="TEMP"; 35 36void setup() { 37 // put your setup code here, to run once: 38 Serial.begin(9600); 39 // Pressure sensor 40 Dps310PressureSensor.begin(Wire); 41 // Radio 42 if (!rf95.init()) 43 { 44 Serial.println("init failed"); 45 while(1); 46 } 47 48 // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on 49 50 // The default transmitter power is 13dBm, using PA_BOOST. 51 // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 52 // you can set transmitter powers from 5 to 23 dBm: 53 rf95.setFrequency(439.0); 54 rf95.setModemConfig(rf95.Bw125Cr48Sf4096); 55 //Serial.print("Conf : "); Serial.println(rf95.Bw125Cr48Sf4096); 56 rf95.setTxPower(power, false); 57} 58 59void loop() { 60 // put your main code here, to run repeatedly: 61 memset(msg,'\\0',sizeof(msg)); 62 // Message de wake up car cot PI ca roupille des fois 63 nbcar = sprintf(msg,"%s","WAKE UP from BARO!"); 64 rf95.send(msg, sizeof(msg)); 65 delay(20000); // pas trop court le dlai 66 memset(msg,'\\0',sizeof(msg)); 67 // DPS310 - Temp 68 ret = Dps310PressureSensor.measureTempOnce(temp, oversampling); 69 if(ret==0){ 70 resTemp=temp; 71 Serial.print("Temp : ");Serial.println(temp); 72 }else{ 73 Serial.print("Err lect Temp : ");Serial.println(ret); 74 } 75// Pression 76 ret = Dps310PressureSensor.measurePressureOnce(pres, oversampling); 77 if(ret==0){ 78 resPres=round(pres/100)+CALIB_PRESS ; 79 Serial.print("Pres : ");Serial.println(pres); 80 }else{ 81 Serial.print("Err lect Pres : ");Serial.println(ret); 82 } 83 // 84 compt+=1; 85 // Formattage message 86 // Arduino ne prend pas en charge simplement les float dans les xprintf (%f) 87 // On passera des entiers la place 88 nbcar = sprintf(msg,"%s%6u%s%6d%s%6d",SOURCE,compt,MESPRES,int(resPres),MESTEMP,int(resTemp*100)); 89 Serial.print(nbcar);Serial.print(" - Msg : ");Serial.println(msg); 90 // ce module est client 91 // Envoi radio 92 rf95.send(msg, sizeof(msg)); 93 94 rf95.waitPacketSent(); 95 96 // Now wait for a reply 97 uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; 98 uint8_t len = sizeof(buf); 99 100 if(rf95.waitAvailableTimeout(5000)) 101 { 102 // Should be a reply message for us now 103 if(rf95.recv(buf, &len)) 104 { 105 Serial.print("Recv OK : "); Serial.println((char*)buf); 106 } 107 else 108 { 109 Serial.println("Recv Err"); 110 } 111 } 112 else 113 { 114 Serial.println("Pas de rception"); 115 } 116 117 // 118 delay(3602000); // 1 heure + 7s - 5s ci-dessus 119 //offsetPwr+=1; 120 //if(offsetPwr>=8){ 121 // offsetPwr=0; 122 //} 123 //Serial.print("Pwr : ");Serial.println(power-offsetPwr); 124 //rf95.setTxPower(power-offsetPwr, false); 125} 126
Downloadable files
Network schema
Network schema
The RFM9x datasheet
The RFM9x datasheet
The RFM9x datasheet
The RFM9x datasheet
Network schema
Network schema
Comments
Only logged in users can leave comments
DGALLENE
0 Followers
•0 Projects
0
0