switching to ABP mode
This commit is contained in:
parent
0651dfcd0e
commit
2edf00c19c
@ -38,7 +38,7 @@
|
||||
#define LMIC_FAILURE_TO Serial
|
||||
|
||||
// Uncomment this to disable all code related to joining
|
||||
// #define DISABLE_JOIN
|
||||
#define DISABLE_JOIN
|
||||
// Uncomment this to disable all code related to ping
|
||||
//#define DISABLE_PING
|
||||
// Uncomment this to disable all code related to beacon tracking.
|
||||
|
59
src/main.cpp
59
src/main.cpp
@ -64,7 +64,7 @@ void PowerSum() { smlOBISWh(SumWh); }
|
||||
// clang-format off
|
||||
OBISHandler OBISHandlers[] = {
|
||||
{{ 0x01, 0x00, 0x01, 0x08, 0x01, 0xff }, &PowerT1}, /* 1- 0: 1. 8.1*255 (T1) */
|
||||
{{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */
|
||||
// {{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */
|
||||
{{ 0, 0 }}
|
||||
};
|
||||
// clang-format on
|
||||
@ -75,6 +75,8 @@ sml_states_t currentState;
|
||||
|
||||
RingBuf<unsigned char, MAX_BUF_SIZE> myBuffer;
|
||||
|
||||
char floatBuffer[20];
|
||||
|
||||
void print_buffer(){
|
||||
|
||||
unsigned int i = 0;
|
||||
@ -104,7 +106,6 @@ void print_buffer(){
|
||||
|
||||
void readByte(unsigned char currentChar)
|
||||
{
|
||||
char floatBuffer[20];
|
||||
unsigned int i = 0, iHandler = 0;
|
||||
// Serial.printf("%02x",currentChar);
|
||||
currentState = smlState(currentChar);
|
||||
@ -115,7 +116,7 @@ void readByte(unsigned char currentChar)
|
||||
myBuffer.push(0x1B);
|
||||
/* reset local vars */
|
||||
T1Wh = -3;
|
||||
SumWh = -3;
|
||||
// SumWh = -3;
|
||||
}
|
||||
else {
|
||||
if (myBuffer.size() < MAX_BUF_SIZE) {
|
||||
@ -149,9 +150,9 @@ void readByte(unsigned char currentChar)
|
||||
Serial.print(floatBuffer);
|
||||
Serial.print(F("\n"));
|
||||
|
||||
Serial.print(F("Power T1+T2 (1-0:1.8.0)..: "));
|
||||
dtostrf(SumWh, 10, 3, floatBuffer);
|
||||
Serial.print(floatBuffer);
|
||||
// Serial.print(F("Power T1+T2 (1-0:1.8.0)..: "));
|
||||
// dtostrf(SumWh, 10, 3, floatBuffer);
|
||||
// Serial.print(floatBuffer);
|
||||
Serial.print(F("\n\n\n\n"));
|
||||
}
|
||||
if (currentState == SML_CHECKSUM_ERROR) {
|
||||
@ -183,7 +184,7 @@ static osjob_t sendjob;
|
||||
// Sleep this many microseconds. Notice that the sending and waiting for downlink
|
||||
// will extend the time between send packets. You have to extract this time
|
||||
// #define SLEEP_INTERVAL 300000
|
||||
#define SLEEP_INTERVAL 30000
|
||||
#define SLEEP_INTERVAL 300000
|
||||
|
||||
// Pin mapping for the MiniPill LoRa with the RFM95 LoRa chip
|
||||
const lmic_pinmap lmic_pins =
|
||||
@ -294,26 +295,42 @@ void do_send(osjob_t* j)
|
||||
Serial.println(F("OP_TXRXPEND, not sending"));
|
||||
} else
|
||||
{
|
||||
Serial.println(F("beginning to read SML ..."));
|
||||
while( Serial2.available() <= 0 ) {
|
||||
__asm__("nop\n\t");
|
||||
uint32_t timeout_cnt = 0;
|
||||
Serial.print(os_getTime());
|
||||
Serial.print(": ");
|
||||
Serial.print(F("beginning to read SML ..."));
|
||||
while( (Serial2.available() <= 0) && (timeout_cnt <= 500) ) {
|
||||
// __asm__("nop\n\t");
|
||||
delay(10);
|
||||
timeout_cnt += 1;
|
||||
}
|
||||
|
||||
while (Serial2.available() > 0) {
|
||||
readByte(Serial2.read());
|
||||
if (timeout_cnt > 500)
|
||||
{
|
||||
Serial.print(F("timeout while reading!!\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
while (Serial2.available() > 0)
|
||||
{
|
||||
readByte(Serial2.read());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Serial.print(F("end of reading SML!!"));
|
||||
}
|
||||
|
||||
Serial.println(F("end of reading SML!!"));
|
||||
// Prepare upstream data transmission at the next possible time.
|
||||
uint8_t dataLength = 2;
|
||||
uint8_t data[dataLength];
|
||||
// uint8_t dataLength = 2;
|
||||
// uint8_t data[dataLength];
|
||||
|
||||
// read vcc and add to bytebuffer
|
||||
int32_t vcc = IntRef.readVref();
|
||||
data[0] = (vcc >> 8) & 0xff;
|
||||
data[1] = (vcc & 0xff);
|
||||
// int32_t vcc = IntRef.readVref();
|
||||
// data[0] = (vcc >> 8) & 0xff;
|
||||
// data[1] = (vcc & 0xff);
|
||||
|
||||
LMIC_setTxData2(1, data, sizeof(data), 0);
|
||||
LMIC_setTxData2(1, (uint8_t* )floatBuffer, sizeof(floatBuffer), 0);
|
||||
Serial.println(F("Packet queued"));
|
||||
// signal with LED that data is queued
|
||||
digitalWrite(SIGNAL_LED, LOW);
|
||||
@ -340,7 +357,7 @@ void setup()
|
||||
// Reset the MAC state. Session and pending data transfers will be discarded.
|
||||
LMIC_reset();
|
||||
// to incrise the size of the RX window.
|
||||
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
|
||||
LMIC_setClockError(MAX_CLOCK_ERROR * 25 / 100);
|
||||
|
||||
// Set static session parameters when using ABP.
|
||||
// Instead of dynamically establishing a session
|
||||
@ -360,7 +377,7 @@ void setup()
|
||||
// prevent some downlink messages, TTN advanced setup is set to the default 5
|
||||
LMIC.rxDelay = 5;
|
||||
// Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
|
||||
LMIC_setDrTxpow(DR_SF7,14);
|
||||
LMIC_setDrTxpow(DR_SF12,14);
|
||||
#endif
|
||||
|
||||
// Configure low power at startup
|
||||
|
@ -19,7 +19,7 @@
|
||||
static const u1_t PROGMEM APPEUI[8]={ 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x23, 0x45 };
|
||||
|
||||
// This should also be in little endian format, see above.
|
||||
static const u1_t PROGMEM DEVEUI[8]={ 0x8D, 0x53, 0x05, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
|
||||
static const u1_t PROGMEM DEVEUI[8]={ 0xD6, 0x33, 0x06, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
|
||||
|
||||
// This key should be in big endian format (or, since it is not really a
|
||||
// number but a block of memory, endianness does not really apply). In
|
||||
@ -32,8 +32,8 @@ static const u1_t PROGMEM APPKEY[16] = { 0x44, 0x99, 0xB4, 0xD3, 0xDB, 0x02, 0x0
|
||||
// set DISABLE_JOIN in config.h in the lmic library
|
||||
|
||||
// LoRaWAN NwkSKey, network session key (TTN msb first)
|
||||
static const PROGMEM u1_t NWKSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
static const PROGMEM u1_t NWKSKEY[16] = { 0xE0, 0x92, 0xEA, 0x35, 0x7C, 0x80, 0xA8, 0x26, 0xAE, 0xB0, 0x7C, 0xF3, 0xD7, 0xCA, 0xAD, 0x85 };
|
||||
// LoRaWAN AppSKey, application session key (TTN msn first)
|
||||
static const u1_t PROGMEM APPSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
static const u1_t PROGMEM APPSKEY[16] = { 0xB2, 0xB5, 0xC8, 0xDF, 0x37, 0x3F, 0xFF, 0x37, 0x39, 0x86, 0xAD, 0x48, 0x51, 0x96, 0xDD, 0x01 };
|
||||
// LoRaWAN DevAddr, end-device address (TTN msb first)
|
||||
static const u4_t DEVADDR = 0x0000000 ;
|
||||
static const u4_t DEVADDR = 0x260B5215 ;
|
||||
|
Loading…
Reference in New Issue
Block a user