this code is using for tests
Dependencies: pulga-lorawan-drv Si1133 BME280
Diff: main.cpp
- Revision:
- 61:169e75494337
- Parent:
- 60:c4f9e9202fb4
- Child:
- 62:e2116ce452eb
--- a/main.cpp Mon Nov 30 19:25:11 2020 +0000 +++ b/main.cpp Fri Dec 04 18:33:43 2020 +0000 @@ -15,6 +15,9 @@ * limitations under the License. */ #include <stdio.h> +#include <ctime> //samira-time +#include <chrono> +#include <iostream> #include "lorawan/LoRaWANInterface.h" #include "lorawan/system/lorawan_data_structures.h" @@ -31,13 +34,14 @@ // Max payload size can be LORAMAC_PHY_MAXPAYLOAD. // This example only communicates with much shorter messages (<30 bytes). // If longer messages are used, these buffers must be changed accordingly. -uint8_t tx_buffer[30]; +//uint8_t tx_buffer[1000]; uint8_t rx_buffer[30]; - +uint8_t tx_buffer[1000] = {0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x0a, 0xa1, 0x05, 0x4c, 0x13, 0x28, 0x18, 0x7b, 0x01, 0xa1, 0x26, 0xca, 0xf7, 0x8e, 0x55, 0x51, 0x58, 0x6f, 0xa8, 0x00, 0x82, 0x64, 0xcf, 0xb0, 0x5e, 0x3d, 0x48, 0x7e, 0x30, 0x2f, 0x4c, 0xc3, 0x37, 0x6b, 0x4d, 0xdb, 0xb6, 0xa9, 0x1b, 0xc9, 0x4c, 0xcc, 0x8e, 0x92, 0x39, 0x8e, 0x4f, 0xe9, 0x3d, 0xb0, 0xa7, 0x48, 0x00, 0xfe, 0x38, 0xa7, 0xcd, 0x57, 0x7e, 0x04, 0x65, 0xb8, 0x2b, 0xf8, 0xc3, 0xbe, 0x33, 0x17, 0xf1, 0xe1, 0xfa, 0x88, 0x7d, 0x3b, 0xd4, 0xa0, 0xce, 0xed, 0x84, 0xed, 0x83, 0xdc, 0x57, 0xcf, 0xe8, 0x5b, 0x7e, 0xc0, 0x5c, 0x6b, 0xbd, 0xa1, 0xdb, 0x67, 0x5d, 0xae, 0xc4, 0x1f, 0x6d, 0x98, 0xf0, 0x97, 0xb6, 0x7a, 0x06, 0x55, 0x97, 0xe6, 0x11, 0x07, 0x52, 0x89, 0x73, 0x65, 0x28, 0x7c, 0xc8, 0x69, 0x39, 0x69, 0xde, 0x12, 0x71, 0x87, 0x43, 0xda, 0xd5, 0x11, 0xbf, 0x81, 0x83, 0x56, 0xa2, 0x01, 0x38, 0x1a, 0x04, 0x50, 0x88, 0x8a, 0x33, 0x0e, 0xc6, 0x2a, 0x43, 0xeb, 0xbf, 0x3c, 0xc9, 0x7c, 0xa6, 0x55, 0xed, 0x33, 0xa0, 0x40}; /* * Sets up an application dependent transmission timer in ms. Used only when Duty Cycling is off for testing */ #define TX_TIMER 10000 +#define DR DR_4 /** * Maximum number of events for the event queue. @@ -102,6 +106,7 @@ mbed::DigitalOut _alive_led(P1_13, 0); mbed::DigitalOut _actuated_led(P1_14,1); + int msg_seq_number; int main(void) { @@ -134,12 +139,29 @@ CONFIRMED_MSG_RETRY_COUNTER); // Enable adaptive data rate - if (lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) { + /* if (lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) { printf("\r\n enable_adaptive_datarate failed! \r\n"); return -1; } printf("\r\n Adaptive data rate (ADR) - Enabled \r\n"); + */ + if (lorawan.disable_adaptive_datarate() != LORAWAN_STATUS_OK) { + printf("\r\ndisable_adaptive_datarate failed! \r\n"); + return -1; + } + + printf("\r\n Adaptive data rate (ADR) - Disabled \r\n"); + + if (lorawan.set_datarate(DR) != LORAWAN_STATUS_OK) { + printf("\r\n Couldn't set data rate to %d! \r\n", DR); + return -1; + } + + printf("\r\n Data rate = %d\r\n", DR); + + + retcode = lorawan.connect(); @@ -159,6 +181,16 @@ return 0; } +static void print_lora_tx_buffer_hex(size_t bufSize){ + char hexa[2*bufSize + 1]; + + for (int i = 0 ; i != bufSize ; i++) { + sprintf(&hexa[2*i], "%02X", tx_buffer[i]); + } + hexa[2*bufSize] = '\0'; + printf("Size = %d. Message to sent: [ %s ]\n", bufSize, hexa); +} + /** * Sends a message to the Network Server */ @@ -168,7 +200,28 @@ int16_t retcode; int32_t sensor_value; - packet_len = sprintf((char *) tx_buffer, "Sensor Value is 10.0\n"); + msg_seq_number = msg_seq_number + 1; + printf("\r\n msgs %d is creating \r\n", msg_seq_number); + + // packet_len = sprintf((char *) tx_buffer, "Ø`C¡¡L({¡&Ê÷UQXo¨dÏ°^=H~0/LÃ7kMÛ¶©ÉLÌ9Oé=°§Hþ8§ÍW~e¸+øþ3ñáú};Ô ÎííÜWÏè[~À\k½¡Ûg]®Ämð¶zUæRse(|Èi9iÞqCÚÕ¿V¢8P3Æ*Cë¿<É|¦Uí3 @", msg_seq_number); + + + // packet_len = sprintf((char *) tx_buffer, "This is message with seq_number = %d \n", msg_seq_number); + + packet_len = 162; + + + printf("packet_len = %d\n", packet_len); + printf("packet_content = %s \n", tx_buffer); + // std::cout<<tx_buffer<<endl; + print_lora_tx_buffer_hex(packet_len); + + //samira-time + auto timenow = + chrono::system_clock::to_time_t(chrono::system_clock::now()); + + cout << ctime(&timenow) << endl; + retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len, MSG_UNCONFIRMED_FLAG); @@ -187,7 +240,9 @@ } printf("\r\n %d bytes scheduled for transmission \r\n", retcode); - memset(tx_buffer, 0, sizeof(tx_buffer)); + // memset(tx_buffer, 0, sizeof(tx_buffer)); + + } /** @@ -236,6 +291,7 @@ printf("\r\n Message Sent to Network Server \r\n"); if (MBED_CONF_LORA_DUTY_CYCLE_ON) { send_message(); + wait(1);//samira-time } break; case TX_TIMEOUT: