hg
Dependencies: LoRaTransmitter mbed BME280 SX1272Lib
Revision 3:4e51739d3a97, committed 2022-06-11
- Comitter:
- aizakharov
- Date:
- Sat Jun 11 14:20:20 2022 +0000
- Parent:
- 1:30ce00fbab55
- Commit message:
- hhjjhkxkhn
Changed in this revision
diff -r 30ce00fbab55 -r 4e51739d3a97 BME280.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BME280.lib Sat Jun 11 14:20:20 2022 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/MACRUM/code/BME280/#bce5ac62b015
diff -r 30ce00fbab55 -r 4e51739d3a97 Grove_LCD_RGB_Backlight.lib --- a/Grove_LCD_RGB_Backlight.lib Fri May 13 15:45:57 2022 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/cmatz3/code/Grove_LCD_RGB_Backlight/#5ce38ef7a7db
diff -r 30ce00fbab55 -r 4e51739d3a97 LoRaTransmitter.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LoRaTransmitter.lib Sat Jun 11 14:20:20 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/aizakharov/code/LoRaTransmitter/#30ce00fbab55
diff -r 30ce00fbab55 -r 4e51739d3a97 main.cpp --- a/main.cpp Fri May 13 15:45:57 2022 +0000 +++ b/main.cpp Sat Jun 11 14:20:20 2022 +0000 @@ -2,8 +2,9 @@ #include "main.h" #include "sx1272-hal.h" #include "debug.h" +#include "BME280.h" -#include "Grove_LCD_RGB_Backlight.h" + /* Set this flag to '1' to display debug messages on the console */ #define DEBUG_MESSAGE 1 @@ -57,14 +58,14 @@ DigitalOut led( LED1 ); #endif -Serial pc(USBTX, USBRX); // tx, rx -AnalogIn voltage(PC_5); -AnalogIn current(A1); +//Serial pc(USBTX, USBRX); // tx, rx +AnalogIn ground(A1); +BME280 sensor(I2C_SDA, I2C_SCL); Ticker measure; -Ticker send; -Grove_LCD_RGB_Backlight lcd(I2C_SDA, I2C_SCL); + -//Grove_LCD_RGB_Backlight rgbLCD(I2C_SDA, I2C_SCL); + + /* * Global variables declarations @@ -106,57 +107,27 @@ int8_t SnrValue = 0.0; //float measured_sinus = 0.0; int16_t j = 0; -float voltage_sinus, current_sinus; -volatile float Vsum = 0,Vmax =0, Vmean = 0, Imax =0, Isum = 0, Imean = 0, Ud = 0, Id = 0, cosi = 0; -volatile double P = 0, P2 = 0, S2 = 0, P1=0, S1=0; +float ground_hum, temperature, pressure, humidity; uint16_t strSize = 0; char str[BUFFER_SIZE]; -char monitor[16]="0", monitor1[16]="0"; + void meas (void) { - j++; - voltage_sinus = voltage*2200; - current_sinus = current*5; - Vsum+=voltage_sinus; - Isum+=current_sinus; - if (voltage_sinus>Vmax) - Vmax=voltage_sinus; - if (current_sinus>Imax) - Imax=current_sinus; - - P=P+(((voltage_sinus-Vmean)*(current_sinus-Imean))*(0.0002/3600000)); - P2=P2+((voltage_sinus-Vmean)*(current_sinus-Imean)); - if((((voltage_sinus-Vmean)*(current_sinus-Imean))*(0.0002/3600000))>0) - S2=S2+((voltage_sinus-Vmean)*(current_sinus-Imean)); + ground_hum = ground; + printf("Ground humidity is %5.2f%%\n\r", ground_hum*100); + printf("%2.2f degC, %04.2f hPa, %2.2f %%\n\r", temperature, pressure, humidity); + strSize = sprintf ( str, "%5.2f%%, %5.2f degC, %5.2f hPa, %5.2f %%", ground_hum*100, temperature, pressure, humidity); + State = TX; - - - if (j>=300) - { - j = 0; - Vmean=Vsum/(300); - Imean = Isum/(300); - P1=P2/300; S1=S2/300; - Ud=(Vmax-Vmean)/1.41; - Id=(Imax-Imean)/1.41; - Vmax = 0; Imax = 0; - - cosi = P2/S2; - P2=0; S2=0; - } + } -void transmit (void) -{ - strSize = sprintf ( str, "W=%10.4fkWh, cos fi=%5.4f, P1=%5.4f, S1=%5.4f", P, cosi, P2, S2); - State = TX; - -} + @@ -242,25 +213,14 @@ - measure.attach_us(&meas, 200); - send.attach(&transmit, 30); + measure.attach(&meas, 5); while( 1 ) { - lcd.setRGB(0, 255, 0); - - - sprintf(monitor, "U=%3.0fV, I=%3.2fA", Ud, Id); - sprintf(monitor1, "P=%8.2f kWh", P); - // Print a message to the LCD. - lcd.locate(0, 0); - lcd.print(monitor); - lcd.locate(0, 1); - lcd.print(monitor1); switch( State ) { @@ -281,6 +241,7 @@ State = LOWPOWER; break; case RX_ERROR: + Radio.Rx( RX_TIMEOUT_VALUE ); State = LOWPOWER; break; case TX_TIMEOUT: @@ -293,7 +254,10 @@ State = LOWPOWER; break; } - + temperature = sensor.getTemperature(); + pressure = sensor.getPressure(); + humidity = sensor.getHumidity(); + wait(5); } }