Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DmTftLibrary eeprom SX1280Lib filesystem mbed
Fork of MSNV2-Terminal_V1-5 by
Diff: main.cpp
- Revision:
- 5:aa8a8d1a5aa7
- Parent:
- 4:41a92fbf702a
- Child:
- 6:784bb5247f0b
--- a/main.cpp Sun Aug 13 19:45:38 2017 +0000 +++ b/main.cpp Mon Aug 14 15:39:18 2017 +0000 @@ -19,8 +19,9 @@ APP_TX_TIMEOUT, }AppStates_t; -#define ID_TERMINAL "1" -#define ID_GATEWAY "1" +#define ID_TERMINAL1 '1' +#define ID_TERMINAL2 '2' +#define ID_GATEWAY '1' float temperature = 0.0 ; float humidite = 0.0 ; @@ -93,20 +94,22 @@ uint8_t id1, id2, id3, id4, id5, id6, id7; float valueTH1, valueTH2, valueTP1, valueTP2; +float OldvalueTH1, OldvalueTH2, OldvalueTP1, OldvalueTP2; char buffer1[32], buffer2[32], buffer3[32], buffer4[32]; int32_t axesA[3], axesM[3], axesG1[3], axesG2[3]; +int32_t OldaxesA[3], OldaxesM[3], OldaxesG1[3], OldaxesG2[3]; -static char *print_double(char* str, double v, int decimalDigits=2) ; -void baud ( int baudrate ) ; - +static char *print_double ( char* str, double v, int decimalDigits=2) ; +void baud ( int baudrate ) ; +void sendRadio ( char TERMINAL, char GATEWAY, float value1, float value2) ; + + void setup () { baud (115200); printf( "\n\n\r SX1280 Terminal IoT LORA MODULATION 2.4GHz (%s)\n\n\r", FIRMWARE_VERSION ); F_CS = 1 ; SD_CS = 1 ; - RxLed = 1 ; - TxLed = 1 ; ANT_SW = 1 ; wait_ms( 500 ); // wait for on board DC/DC start-up time @@ -115,7 +118,6 @@ Radio.SetRegulatorMode ( USE_DCDC ); // Can also be set in LDO mode but consume more power memset ( &Buffer, 0x00, BufferSize ); - RxLed = 0; TxLed = 0; @@ -168,16 +170,15 @@ } void loop () { - wait(4); + + TxLed = 0 ; + RxLed = 0 ; + wait (1) ; + F_CS = 1 ; + SD_CS = 1 ; + ANT_SW = 1 ; + wait( 0.5 ); // wait for on board DC/DC start-up time - F_CS = 1 ; - SD_CS = 1 ; - RxLed = 1 ; - TxLed = 1 ; - ANT_SW = 1 ; - - wait( 0.5 ); // wait for on board DC/DC start-up time - /* Enable all sensors */ hum_temp->enable (); press_temp->enable (); @@ -185,32 +186,23 @@ accelerometer->enable (); acc_gyro->enable_x (); acc_gyro->enable_g (); + wait(0.5); - //wait_ms( 500 ); // wait for on board DC/DC start-up time - - wait(0.5); printf("============================================================== \r\n"); - - hum_temp->get_temperature (&valueTH1) ; wait_ms( 10 ); - hum_temp->get_humidity (&valueTH2) ; wait_ms( 10 ); - + hum_temp->get_temperature (&valueTH1) ; + hum_temp->get_humidity (&valueTH2) ; printf("HTS221 : [temp] %7s C, [hum] %s%%\r\n" , print_double(buffer1, valueTH1), print_double(buffer2, valueTH2)); - - press_temp->get_temperature (&valueTP1) ; - press_temp->get_pressure (&valueTP2) ; + press_temp->get_temperature (&valueTP1) ; + press_temp->get_pressure (&valueTP2) ; printf("LPS22HB : [temp] %7s C, [press] %s mbar\r\n" , print_double(buffer3, valueTP1), print_double(buffer4, valueTP2)); - - magnetometer->get_m_axes (axesM) ; + magnetometer->get_m_axes (axesM) ; printf("LSM303AGR : [mag/mgauss] %6ld, %6ld, %6ld\r\n", axesM[0], axesM[1], axesM[2]); - - accelerometer->get_x_axes (axesA) ; + accelerometer->get_x_axes (axesA) ; printf("LSM303AGR : [acc/mg] %6ld, %6ld, %6ld\r\n", axesA[0], axesA[1], axesA[2]); - - acc_gyro->get_x_axes (axesG1) ; - acc_gyro->get_g_axes (axesG2) ; + acc_gyro->get_x_axes (axesG1) ; printf("LSM6DSL : [acc/mg] %6ld, %6ld, %6ld\r\n", axesG1[0], axesG1[1], axesG1[2]); + acc_gyro->get_g_axes (axesG2) ; printf("LSM6DSL : [gyro/mdps] %6ld, %6ld, %6ld\r\n", axesG2[0], axesG2[1], axesG2[2]); - printf("============================================================== \r\n"); /* Disable all sensors */ @@ -220,32 +212,24 @@ accelerometer->disable (); acc_gyro->disable_x (); acc_gyro->disable_g (); - - - - TxLed = 1 ; - //int n = sprintf ( Message, "MSG DATA IOT TERMINAL: %d", cptr++) ; - memset ( &Buffer , 0x00, BufferSize ); - memset ( &Message, 0x00, BufferSize ); - - int n = sprintf ( Message, "%1s %1s %s %s %s&", - ID_TERMINAL, - ID_GATEWAY, - print_double(buffer1, valueTH1), - print_double(buffer2, valueTH2), - print_double(buffer3, valueTP2) ) ; - - memcpy ( Buffer , Message , MESSAGESIZE ); - printf ( "*** TERM *** Message = %s \r\n", Buffer ); - Radio.SetDioIrqParams ( TxIrqMask , TxIrqMask , IRQ_RADIO_NONE, IRQ_RADIO_NONE ); - Radio.SendPayload ( Buffer , BufferSize,( TickTime_t ){ RX_TIMEOUT_TICK_SIZE, TX_TIMEOUT_VALUE } ); - TxLed = 0 ; - - + if ( abs(OldvalueTH1 - valueTH1) > 0.25F || + abs(OldvalueTH2 - valueTH2) > 0.25F || + abs(OldaxesA[0] - axesA[0]) > 20 ) { + OldvalueTH1 = valueTH1 ; + OldvalueTH2 = valueTH2 ; + OldaxesA[0] = axesA[0] ; + sendRadio (ID_TERMINAL1, ID_GATEWAY, valueTH1, valueTH2) ; + } + if ( abs(OldvalueTP1 - valueTP1) > 0.25F || + abs(OldvalueTP2 - valueTP2) > 0.25F ) { + OldvalueTP1 = valueTP1 ; + OldvalueTP2 = valueTP2 ; + sendRadio (ID_TERMINAL2, ID_GATEWAY, valueTP1, valueTP2) ; + } + } - - + int main( ) { setup () ; while (1) loop () ; } @@ -264,6 +248,22 @@ printf("rssi: %d; snr: %d\n\r", RssiValue, SnrValue ); */ +void sendRadio (char TERMINAL, char GATEWAY, float value1, float value2) { + TxLed = 1 ; + memset ( &Buffer , 0x00, BufferSize ); + memset ( &Message, 0x00, BufferSize ); + int n = sprintf ( Message, "%c%c%5s%5s", + TERMINAL, + GATEWAY, + print_double(buffer1, value1), + print_double(buffer2, value2) ); + memcpy ( Buffer , Message , MESSAGESIZE ); + printf ( "*** TERM *** Message = %s \r\n", Buffer ); + Radio.SetDioIrqParams ( TxIrqMask , TxIrqMask , IRQ_RADIO_NONE, IRQ_RADIO_NONE ); + Radio.SendPayload ( Buffer , BufferSize,( TickTime_t ){ RX_TIMEOUT_TICK_SIZE, TX_TIMEOUT_VALUE } ); + TxLed = 0 ; + } + /* Helper function for printing floats & doubles */