A demo application for HXC900 LoRaWAN module using Nucleo-L053R8.

Dependencies:   mbed

Committer:
fahadmirza
Date:
Thu Sep 13 15:29:47 2018 +0000
Revision:
19:0c90e38fc9c5
Parent:
17:e682a18c3914
Child:
20:1ed8723a3a87
Removed STRING uplink;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fahadmirza 4:511677d804ac 1 /*
fahadmirza 4:511677d804ac 2 _ _ _____ _______
fahadmirza 4:511677d804ac 3 | | | | |_ _| |__ __|
fahadmirza 4:511677d804ac 4 | |__| | __ ___ __ | | ___ | |
fahadmirza 4:511677d804ac 5 | __ |/ _` \ \/ / | | / _ \| |
fahadmirza 4:511677d804ac 6 | | | | (_| |> < _| || (_) | |
fahadmirza 4:511677d804ac 7 |_| |_|\__,_/_/\_\_____\___/|_|
fahadmirza 4:511677d804ac 8 (C)2017 HaxIoT
fahadmirza 4:511677d804ac 9 */
fahadmirza 4:511677d804ac 10 /*******************************************************************************
fahadmirza 7:3c5d342068dd 11 * File : lora_conf.h
fahadmirza 4:511677d804ac 12 * Author : Fahad Mirza (Haxiot)
fahadmirza 4:511677d804ac 13 * Version : V1.0.0
fahadmirza 8:60cfc0029421 14 * Modified: 18-July-2018
fahadmirza 7:3c5d342068dd 15 * Brief : LoRaWAN Configuration
fahadmirza 4:511677d804ac 16 ******************************************************************************
fahadmirza 4:511677d804ac 17 * @attention
fahadmirza 4:511677d804ac 18 *
fahadmirza 4:511677d804ac 19 * <h2><center>&copy; COPYRIGHT(c) 2017 Haxiot</center></h2>
fahadmirza 4:511677d804ac 20 *
fahadmirza 4:511677d804ac 21 * Redistribution and use in source and binary forms, with or without modification,
fahadmirza 4:511677d804ac 22 * are permitted provided that the following conditions are met:
fahadmirza 4:511677d804ac 23 * 1. Redistributions of source code must retain the above copyright notice,
fahadmirza 4:511677d804ac 24 * this list of conditions and the following disclaimer.
fahadmirza 4:511677d804ac 25 * 2. Redistributions in binary form must reproduce the above copyright notice,
fahadmirza 4:511677d804ac 26 * this list of conditions and the following disclaimer in the documentation
fahadmirza 4:511677d804ac 27 * and/or other materials provided with the distribution.
fahadmirza 4:511677d804ac 28 * 3. Neither the name of Haxiot nor the names of its contributors
fahadmirza 4:511677d804ac 29 * may be used to endorse or promote products derived from this software
fahadmirza 4:511677d804ac 30 * without specific prior written permission.
fahadmirza 4:511677d804ac 31 *
fahadmirza 4:511677d804ac 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
fahadmirza 4:511677d804ac 33 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fahadmirza 4:511677d804ac 34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
fahadmirza 4:511677d804ac 35 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
fahadmirza 4:511677d804ac 36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
fahadmirza 4:511677d804ac 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
fahadmirza 4:511677d804ac 38 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
fahadmirza 4:511677d804ac 39 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
fahadmirza 4:511677d804ac 40 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
fahadmirza 4:511677d804ac 41 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
fahadmirza 4:511677d804ac 42 *
fahadmirza 4:511677d804ac 43 ******************************************************************************
fahadmirza 4:511677d804ac 44 */
fahadmirza 4:511677d804ac 45
fahadmirza 4:511677d804ac 46 #ifndef __LORA_CONF_H
fahadmirza 4:511677d804ac 47 #define __LORA_CONF_H
fahadmirza 4:511677d804ac 48
fahadmirza 4:511677d804ac 49 #ifdef __cplusplus
fahadmirza 4:511677d804ac 50 extern "C" {
fahadmirza 4:511677d804ac 51 #endif
fahadmirza 4:511677d804ac 52
fahadmirza 6:1d09b7960d57 53 #include <ctype.h>
fahadmirza 6:1d09b7960d57 54 #include <string.h>
fahadmirza 4:511677d804ac 55
fahadmirza 15:2860c960d2ff 56 /* Macros --------------------------------------------------------------------*/
fahadmirza 15:2860c960d2ff 57 #define SENSORS_MEASURE_CYCLE (15000U) // Send packet every 15s
fahadmirza 4:511677d804ac 58
fahadmirza 5:53302861bfea 59 // Uplink packet acknowledgment configuration
fahadmirza 5:53302861bfea 60 #define UNCONFIRMED 0
fahadmirza 5:53302861bfea 61 #define CONFIRMED 1
fahadmirza 4:511677d804ac 62
fahadmirza 4:511677d804ac 63
fahadmirza 15:2860c960d2ff 64 /* Function declarations -----------------------------------------------------*/
fahadmirza 8:60cfc0029421 65 static void tolower_array(char *array, uint8_t arraySize);
fahadmirza 8:60cfc0029421 66
fahadmirza 4:511677d804ac 67 /* Private function definitions ----------------------------------------------*/
fahadmirza 4:511677d804ac 68 /******************************************************************************
fahadmirza 4:511677d804ac 69 * @Brief : Uplink packet handler for lora_driver
fahadmirza 4:511677d804ac 70 * @Param : Pointer for payload buffer, data size, ack configuration and port
fahadmirza 15:2860c960d2ff 71 * @Return: None
fahadmirza 4:511677d804ac 72 ******************************************************************************/
fahadmirza 4:511677d804ac 73 static void GetSensorData(uint8_t *buffer, uint8_t *dataSize, uint8_t *ack, uint8_t *port)
fahadmirza 4:511677d804ac 74 {
fahadmirza 4:511677d804ac 75 // Prepare an unconfirmed uplink packet for port 2
fahadmirza 4:511677d804ac 76 uint8_t size = 0;
fahadmirza 4:511677d804ac 77
fahadmirza 19:0c90e38fc9c5 78 float temperatureValue = temperatureSensor.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
fahadmirza 19:0c90e38fc9c5 79 uint16_t temperatureValueInt = temperatureValue * 3300; // Change the value to be in the 0 to 3300 range
fahadmirza 19:0c90e38fc9c5 80
fahadmirza 19:0c90e38fc9c5 81 buffer[size++] = (temperatureValueInt >> 8) & 0xFF;
fahadmirza 19:0c90e38fc9c5 82 buffer[size++] = temperatureValueInt & 0xFF;
fahadmirza 19:0c90e38fc9c5 83 buffer[size++] = slideSwitch;
fahadmirza 4:511677d804ac 84
fahadmirza 4:511677d804ac 85 *dataSize = size;
fahadmirza 4:511677d804ac 86 *ack = UNCONFIRMED;
fahadmirza 4:511677d804ac 87 *port = 2;
fahadmirza 4:511677d804ac 88 }
fahadmirza 4:511677d804ac 89
fahadmirza 4:511677d804ac 90 /******************************************************************************
fahadmirza 4:511677d804ac 91 * @Brief : Downlink packet handler for lora_driver
fahadmirza 8:60cfc0029421 92 * Valid downlink messages are: 'red', 'green', 'blue' and 'off'
fahadmirza 4:511677d804ac 93 * @Param : Payload buffer, data size, ack configuration and port
fahadmirza 15:2860c960d2ff 94 * @Return: None
fahadmirza 4:511677d804ac 95 ******************************************************************************/
fahadmirza 4:511677d804ac 96 static void LedControl(uint8_t *buffer, uint8_t dataSize, uint8_t ack, uint8_t port)
fahadmirza 4:511677d804ac 97 {
fahadmirza 8:60cfc0029421 98 tolower_array((char *)buffer, dataSize);
fahadmirza 6:1d09b7960d57 99
fahadmirza 6:1d09b7960d57 100 if(strncmp("red", (const char *)buffer, 3) == 0)
fahadmirza 6:1d09b7960d57 101 {
fahadmirza 6:1d09b7960d57 102 redLED = 1;
fahadmirza 6:1d09b7960d57 103 greenLED = 0;
fahadmirza 6:1d09b7960d57 104 blueLED = 0;
fahadmirza 6:1d09b7960d57 105 }
fahadmirza 6:1d09b7960d57 106 else if(strncmp("green", (const char *)buffer, 5) == 0)
fahadmirza 6:1d09b7960d57 107 {
fahadmirza 6:1d09b7960d57 108 redLED = 0;
fahadmirza 6:1d09b7960d57 109 greenLED = 1;
fahadmirza 6:1d09b7960d57 110 blueLED = 0;
fahadmirza 6:1d09b7960d57 111 }
fahadmirza 6:1d09b7960d57 112 else if(strncmp("blue", (const char *)buffer, 4) == 0)
fahadmirza 4:511677d804ac 113 {
fahadmirza 6:1d09b7960d57 114 redLED = 0;
fahadmirza 6:1d09b7960d57 115 greenLED = 0;
fahadmirza 6:1d09b7960d57 116 blueLED = 1;
fahadmirza 6:1d09b7960d57 117 }
fahadmirza 6:1d09b7960d57 118 else if(strncmp("off", (const char *)buffer, 4) == 0)
fahadmirza 6:1d09b7960d57 119 {
fahadmirza 6:1d09b7960d57 120 redLED = 0;
fahadmirza 6:1d09b7960d57 121 greenLED = 0;
fahadmirza 6:1d09b7960d57 122 blueLED = 0;
fahadmirza 6:1d09b7960d57 123 }
fahadmirza 6:1d09b7960d57 124 }
fahadmirza 6:1d09b7960d57 125
fahadmirza 8:60cfc0029421 126
fahadmirza 8:60cfc0029421 127 /******************************************************************************
fahadmirza 8:60cfc0029421 128 * @Brief : Upper case to lower case for an array
fahadmirza 8:60cfc0029421 129 * @Param : Pointer to array containing characters and array size
fahadmirza 15:2860c960d2ff 130 * @Return: None
fahadmirza 8:60cfc0029421 131 ******************************************************************************/
fahadmirza 8:60cfc0029421 132 static void tolower_array(char *array, uint8_t arraySize)
fahadmirza 6:1d09b7960d57 133 {
fahadmirza 8:60cfc0029421 134 for(uint8_t i = 0; i < arraySize; i++)
fahadmirza 6:1d09b7960d57 135 {
fahadmirza 8:60cfc0029421 136 array[i] = tolower(array[i]);
fahadmirza 4:511677d804ac 137 }
fahadmirza 4:511677d804ac 138 }
fahadmirza 4:511677d804ac 139
fahadmirza 4:511677d804ac 140 #ifdef __cplusplus
fahadmirza 4:511677d804ac 141 }
fahadmirza 4:511677d804ac 142 #endif /* __cplusplus */
fahadmirza 4:511677d804ac 143
fahadmirza 4:511677d804ac 144 #endif