Got examples/periodic working
This commit is contained in:
parent
baf7df4a54
commit
5f7b457fcc
59
README.md
59
README.md
@ -125,3 +125,62 @@ Possible outpout:
|
|||||||
What can be seen is that after sending the "join" message, the LMIC stack waits
|
What can be seen is that after sending the "join" message, the LMIC stack waits
|
||||||
5 seconds for the receive window and receives the acknowledgement from the LoRa gateway.
|
5 seconds for the receive window and receives the acknowledgement from the LoRa gateway.
|
||||||
|
|
||||||
|
## Example "periodic"
|
||||||
|
Directory: /examples/periodic
|
||||||
|
|
||||||
|
Modifications necessary:
|
||||||
|
|
||||||
|
File /examples/periodic/main.c:
|
||||||
|
|
||||||
|
* Adapt "application router ID (LSBF)" like already described under examples/join.
|
||||||
|
* Adapt "unique device ID (LSBF)" like already described under examples/join.
|
||||||
|
* Adapt "device-specific AES key " like already described under examples/join.
|
||||||
|
|
||||||
|
File /examples/periodic/sensor.c:
|
||||||
|
|
||||||
|
Added code that reads the CPU temperature of the RPi and returns it as a 2 byte integer
|
||||||
|
value.
|
||||||
|
|
||||||
|
This examples does a "joins" the network and then sends a sensor value (the CPU temperature)
|
||||||
|
every 60 seconds as an unconfirmed message with a payload of 2 bytes.
|
||||||
|
|
||||||
|
cd examples/periodic
|
||||||
|
make clean
|
||||||
|
make
|
||||||
|
sudo ./build/periodic.out
|
||||||
|
|
||||||
|
Possible output:
|
||||||
|
|
||||||
|
000000000 HAL: Initializing ...
|
||||||
|
000000004 HAL: Set radio RST pin to 0x00
|
||||||
|
000000005 HAL: Wait until 000000006 ms
|
||||||
|
000000006 HAL: Set radio RST pin to 0x02
|
||||||
|
000000006 HAL: Wait until 000000011 ms
|
||||||
|
000000013 HAL: Receiving ...
|
||||||
|
000000041 Debug: Initializing
|
||||||
|
000000041 Debug: JOINING
|
||||||
|
000004897 Debug: EV_TXSTART
|
||||||
|
000004898 HAL: Sending ...
|
||||||
|
000009960 HAL: Receiving ...
|
||||||
|
000009961 HAL: Wait until 000009962 ms
|
||||||
|
000010033 Debug: JOINED
|
||||||
|
000010034 Debug: 54230
|
||||||
|
000010034 Debug: Label 'val = ' value 0xd3d6
|
||||||
|
000010034 Debug: EV_TXSTART
|
||||||
|
000010034 HAL: Sending ...
|
||||||
|
000011081 HAL: Receiving ...
|
||||||
|
000011081 HAL: Wait until 000011082 ms
|
||||||
|
000012128 HAL: Receiving ...
|
||||||
|
000012128 HAL: Wait until 000012130 ms
|
||||||
|
000016360 Debug: TXCOMPLETE
|
||||||
|
000070068 Debug: 53692
|
||||||
|
000070068 Debug: Label 'val = ' value 0xd1bc
|
||||||
|
000070069 Debug: EV_TXSTART
|
||||||
|
000070070 HAL: Sending ...
|
||||||
|
000071117 HAL: Receiving ...
|
||||||
|
000071117 HAL: Wait until 000071118 ms
|
||||||
|
000072164 HAL: Receiving ...
|
||||||
|
000072164 HAL: Wait until 000072165 ms
|
||||||
|
000076734 Debug: TXCOMPLETE
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,14 +39,13 @@ extern u2_t readsensor(void);
|
|||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
|
|
||||||
// application router ID (LSBF)
|
// application router ID (LSBF)
|
||||||
static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
|
static const u1_t APPEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
// unique device ID (LSBF)
|
// unique device ID (LSBF)
|
||||||
static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
|
static const u1_t DEVEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
// device-specific AES key (derived from device EUI)
|
// device-specific AES key (derived from device EUI)
|
||||||
static const u1_t DEVKEY[16] = { 0xAB, 0x89, 0xEF, 0xCD, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA };
|
static const u1_t DEVKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
// APPLICATION CALLBACKS
|
// APPLICATION CALLBACKS
|
||||||
@ -113,7 +112,7 @@ static void reportfunc (osjob_t* j) {
|
|||||||
u2_t val = readsensor();
|
u2_t val = readsensor();
|
||||||
debug_val("val = ", val);
|
debug_val("val = ", val);
|
||||||
// prepare and schedule data for transmission
|
// prepare and schedule data for transmission
|
||||||
LMIC.frame[0] = val << 8;
|
LMIC.frame[0] = val >> 8;
|
||||||
LMIC.frame[1] = val;
|
LMIC.frame[1] = val;
|
||||||
LMIC_setTxData2(1, LMIC.frame, 2, 0); // (port 1, 2 bytes, unconfirmed)
|
LMIC_setTxData2(1, LMIC.frame, 2, 0); // (port 1, 2 bytes, unconfirmed)
|
||||||
// reschedule job in 60 seconds
|
// reschedule job in 60 seconds
|
||||||
|
@ -1,40 +1,73 @@
|
|||||||
/*
|
//
|
||||||
* Copyright (c) 2014-2016 IBM Corporation.
|
// BSD 3-Clause License
|
||||||
* All rights reserved.
|
//
|
||||||
*
|
// Hardware Abstraction Layer (HAL) targeted to Raspberry Pi and
|
||||||
* Redistribution and use in source and binary forms, with or without
|
// Dragino LoRa/GPS HAT
|
||||||
* modification, are permitted provided that the following conditions are met:
|
//
|
||||||
* * Redistributions of source code must retain the above copyright
|
// Copyright (c) 2017, Wolfgang Klenk
|
||||||
* notice, this list of conditions and the following disclaimer.
|
// All rights reserved.
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
//
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
// Redistribution and use in source and binary forms, with or without
|
||||||
* documentation and/or other materials provided with the distribution.
|
// modification, are permitted provided that the following conditions are met:
|
||||||
* * Neither the name of the <organization> nor the
|
//
|
||||||
* names of its contributors may be used to endorse or promote products
|
// * Redistributions of source code must retain the above copyright notice, this
|
||||||
* derived from this software without specific prior written permission.
|
// list of conditions and the following disclaimer.
|
||||||
*
|
//
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
// and/or other materials provided with the distribution.
|
||||||
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
//
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
// * Neither the name of the copyright holder nor the names of its
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
// contributors may be used to endorse or promote products derived from
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
// this software without specific prior written permission.
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
//
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
*/
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
#include "lmic.h"
|
#include <fcntl.h>
|
||||||
#include "hw.h"
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
// use PB12 (DIP switch 1) as sensor value
|
#include "oslmic.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
// Nothing to do
|
||||||
void initsensor () {
|
void initsensor () {
|
||||||
RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // clock enable port B
|
|
||||||
hw_cfg_pin(GPIOB, 12, GPIOCFG_MODE_INP | GPIOCFG_OSPEED_40MHz | GPIOCFG_OTYPE_OPEN); // PB12
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read PB12
|
// Read CPU temperature
|
||||||
u2_t readsensor () {
|
u2_t readsensor () {
|
||||||
return ((GPIOB->IDR & (1 << 12)) != 0);
|
static const char* fn = "/sys/class/thermal/thermal_zone0/temp";
|
||||||
|
int fd = open(fn, O_RDONLY);
|
||||||
|
if(fd < 0) {
|
||||||
|
perror(fn);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
char temp[10];
|
||||||
|
int rc = read(fd, &temp, 10);
|
||||||
|
if (rc < 0) {
|
||||||
|
perror("Read CPU temperature.");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
debug_str(temp);
|
||||||
|
u2_t t = (u2_t) atoi(temp);
|
||||||
|
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
40
examples/periodic/sensor.c.lmic_1.6_original
Normal file
40
examples/periodic/sensor.c.lmic_1.6_original
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014-2016 IBM Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "lmic.h"
|
||||||
|
#include "hw.h"
|
||||||
|
|
||||||
|
// use PB12 (DIP switch 1) as sensor value
|
||||||
|
void initsensor () {
|
||||||
|
RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // clock enable port B
|
||||||
|
hw_cfg_pin(GPIOB, 12, GPIOCFG_MODE_INP | GPIOCFG_OSPEED_40MHz | GPIOCFG_OTYPE_OPEN); // PB12
|
||||||
|
}
|
||||||
|
|
||||||
|
// read PB12
|
||||||
|
u2_t readsensor () {
|
||||||
|
return ((GPIOB->IDR & (1 << 12)) != 0);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user