Commit ba2a719f authored by Frank Radzio 's avatar Frank Radzio

Weathernode_01 und 02 gebaut aber noch nicht getestet

parent d917fc0b
/**************************************************************
*
* Weather Node 01
* Weather Node 0
*
* Sensortyp BMP280
*
......@@ -13,7 +13,7 @@
* Hardware:
* - Arduino Pro-Mini 3.3V
* - RFM95W
* - kein Sensor
* - BMP280 sensor.
*
* Software:
* - LMIC https://github.com/matthijskooijman/arduino-lmic
......@@ -29,7 +29,7 @@
/************************************************************
* TheThingsNetwork Payload function:
function Decoder(bytes, port)
function Decoder(bytes, port)
{
var retValue = {
bytes: bytes
......@@ -38,9 +38,26 @@
retValue.batt = bytes[0] / 10.0;
if (retValue.batt === 0)
delete retValue.batt;
return retValue;
}
if (bytes.length >= 2)
{
retValue.humidity = bytes[1];
if (retValue.humidity === 0)
delete retValue.humidity;
}
if (bytes.length >= 3)
{
retValue.temperature = (((bytes[2] << 8) | bytes[3]) / 10.0) - 40.0;
}
if (bytes.length >= 5)
{
retValue.pressure = ((bytes[4] << 8) | bytes[5]);
if (retValue.pressure === 0)
delete retValue.pressure;
}
return retValue;
}
*
*
***********************************************************/
......@@ -52,8 +69,13 @@
#include <lmic.h>
#include <hal/hal.h>
#include <LowPower.h>
#include "adcvcc.h"
/**********************************************************
* Notwendige Libs für den BME280
**********************************************************/
#include <Wire.h>
#include "adcvcc.h"
#include "BME280I2C.h"
/**********************************************************
* Defines
**********************************************************/
......@@ -93,8 +115,8 @@ const lmic_pinmap lmic_pins = {
/*****************************************************
* ABP
*****************************************************/
static const PROGMEM u1_t NWKSKEY[16] = { ---- }; // LoRaWAN NwkSKey, network session key
static const u1_t PROGMEM APPSKEY[16] = { ----- }; // LoRaWAN AppSKey, application session key
static const PROGMEM u1_t NWKSKEY[16] = { }; // LoRaWAN NwkSKey, network session key
static const u1_t PROGMEM APPSKEY[16] = { }; // LoRaWAN AppSKey, application session key
static const u4_t DEVADDR = 0x000000 ; // LoRaWAN end-device address (DevAddr)
/****************************************************
* OTAA
......@@ -110,6 +132,19 @@ void os_getDevKey (u1_t* buf) { }
* global enviromental parameters
***************************************************/
static osjob_t sendjob;
/***************************************************
* Die Variablen für den BME280
***************************************************/
static float temp = 0.0;
static float pressure = 0.0;
static float humidity = 0.0;
/**************************************************
* Das bme Objekt
* Default : forced mode, standby time = 1000 ms
* Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
*/
BME280I2C bme;
/***************************************************************
* Hier das Sende Intervall festlegen
* TRACKINGINTERVAL alle 10 Sekunden
......@@ -158,6 +193,19 @@ ISR(ADC_vect)
*******************************************************************************/
void updateEnvParameters()
{
/***********************************************************************************
* Die drei Variablen für Temperatur, Luftdruck und Luftfeuchtigkeit werden befüllt
* Aufruf vor jedem Senden damit die Werte auch aktuell sind
***********************************************************************************/
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
temp = bme.temp();
pressure = bme.pres(); // 1 = hPa (milliBar)
humidity = bme.hum();
}
/*******************************************************************************
* onEvent
......@@ -251,22 +299,46 @@ void do_send(osjob_t* j)
// Prepare upstream data transmission at the next possible time.
// Here the sensor information should be retrieved
// Pressure: 300...1100 hPa
// Temperature: -40…85°C
updateEnvParameters();
int batt = (int)(readVcc() / 100); // readVCC returns mVolt need just 100mVolt steps
byte batvalue = (byte)batt; // no problem putting it into a int.
#ifdef SHOW_DEBUGINFO
#ifdef SHOW_DEBUGINFO
debugPrint(F("T="));
debugPrintLn(temp);
debugPrint(F("P="));
debugPrintLn(pressure);
debugPrint(F("H="));
debugPrintLn(humidity);
debugPrint(F("B="));
debugPrintLn(batt);
debugPrint(F("BV="));
debugPrintLn(batvalue);
#endif
int t = (int)((temp + 40.0) * 10.0);
// t = t + 40; => t [-40..+85] => [0..125] => t = t * 10; => t [0..125] => [0..1250]
int p = (int)(pressure); // p [300..1100]
int h = (int)(humidity);
// Der Payload wird vorbereitet
unsigned char mydata[6];
mydata[0] = batvalue;
mydata[1] = h & 0xFF;
mydata[2] = t >> 8;
mydata[3] = t & 0xFF;
mydata[4] = p >> 8;
mydata[5] = p & 0xFF;
// Die Daten werden übertragen
// Wichtig ist an dieser Stelle das der Port 1 genutzt wird
LMIC_setTxData2(1, mydata, sizeof(mydata), 0);
debugPrintLn(F("PQ")); //Packet queued
}
......@@ -287,7 +359,28 @@ void do_send(osjob_t* j)
void setup() {
Serial.begin(115200);
debugPrintLn(F("Starting"));
// Init BME208
if (!bme.begin())
{
debugPrintLn(F("No valid bme280 sensor!"));
delay(1000); // allow serial to send.
while (1)
{
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
Serial.println("Found BME280 sensor! Success.");
break;
case BME280::ChipModel_BMP280:
Serial.println("Found BMP280 sensor! No Humidity available.");
break;
default:
Serial.println("Found UNKNOWN sensor! Error!");
}
}
// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
......@@ -397,11 +490,13 @@ void loop()
LMIC_transmitted = 0;
LMIC_event_Timeout = 0;
//debugPrintLn(F("Going to sleep."));
//delay(1000); // allow serial to send.
/********************************************************************************
* Hier wird der Node in den Schlafmodus gelegt
*******************************************************************************/
#ifdef SHOW_DEBUGINFO
debugPrintLn(F("Going to sleep."));
#endif
if (interval > TRACKINGINTERVAL)
{
for (int i = 0; i < interval; i++)
......@@ -411,5 +506,7 @@ void loop()
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
}
//debugPrintLn("---");
#ifdef SHOW_DEBUGINFO
debugPrintLn("---");
#endif
}
/**************************************************************
*
* Weather Node 01
* Weather Node 02
*
* Sensortyp BME280
*
......@@ -13,7 +13,7 @@
* Hardware:
* - Arduino Pro-Mini 3.3V
* - RFM95W
* - kein Sensor
* - BME280 sensor.
*
* Software:
* - LMIC https://github.com/matthijskooijman/arduino-lmic
......@@ -29,7 +29,7 @@
/************************************************************
* TheThingsNetwork Payload function:
function Decoder(bytes, port)
function Decoder(bytes, port)
{
var retValue = {
bytes: bytes
......@@ -38,9 +38,26 @@
retValue.batt = bytes[0] / 10.0;
if (retValue.batt === 0)
delete retValue.batt;
return retValue;
}
if (bytes.length >= 2)
{
retValue.humidity = bytes[1];
if (retValue.humidity === 0)
delete retValue.humidity;
}
if (bytes.length >= 3)
{
retValue.temperature = (((bytes[2] << 8) | bytes[3]) / 10.0) - 40.0;
}
if (bytes.length >= 5)
{
retValue.pressure = ((bytes[4] << 8) | bytes[5]);
if (retValue.pressure === 0)
delete retValue.pressure;
}
return retValue;
}
*
*
***********************************************************/
......@@ -52,8 +69,13 @@
#include <lmic.h>
#include <hal/hal.h>
#include <LowPower.h>
#include "adcvcc.h"
/**********************************************************
* Notwendige Libs für den BME280
**********************************************************/
#include <Wire.h>
#include "adcvcc.h"
#include "BME280I2C.h"
/**********************************************************
* Defines
**********************************************************/
......@@ -93,8 +115,8 @@ const lmic_pinmap lmic_pins = {
/*****************************************************
* ABP
*****************************************************/
static const PROGMEM u1_t NWKSKEY[16] = { ---- }; // LoRaWAN NwkSKey, network session key
static const u1_t PROGMEM APPSKEY[16] = { ----- }; // LoRaWAN AppSKey, application session key
static const PROGMEM u1_t NWKSKEY[16] = { }; // LoRaWAN NwkSKey, network session key
static const u1_t PROGMEM APPSKEY[16] = { }; // LoRaWAN AppSKey, application session key
static const u4_t DEVADDR = 0x000000 ; // LoRaWAN end-device address (DevAddr)
/****************************************************
* OTAA
......@@ -110,6 +132,19 @@ void os_getDevKey (u1_t* buf) { }
* global enviromental parameters
***************************************************/
static osjob_t sendjob;
/***************************************************
* Die Variablen für den BME280
***************************************************/
static float temp = 0.0;
static float pressure = 0.0;
static float humidity = 0.0;
/**************************************************
* Das bme Objekt
* Default : forced mode, standby time = 1000 ms
* Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
*/
BME280I2C bme;
/***************************************************************
* Hier das Sende Intervall festlegen
* TRACKINGINTERVAL alle 10 Sekunden
......@@ -158,6 +193,19 @@ ISR(ADC_vect)
*******************************************************************************/
void updateEnvParameters()
{
/***********************************************************************************
* Die drei Variablen für Temperatur, Luftdruck und Luftfeuchtigkeit werden befüllt
* Aufruf vor jedem Senden damit die Werte auch aktuell sind
***********************************************************************************/
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
temp = bme.temp();
pressure = bme.pres(); // 1 = hPa (milliBar)
humidity = bme.hum();
}
/*******************************************************************************
* onEvent
......@@ -251,23 +299,47 @@ void do_send(osjob_t* j)
// Prepare upstream data transmission at the next possible time.
// Here the sensor information should be retrieved
// Pressure: 300...1100 hPa
// Temperature: -40…85°C
updateEnvParameters();
int batt = (int)(readVcc() / 100); // readVCC returns mVolt need just 100mVolt steps
byte batvalue = (byte)batt; // no problem putting it into a int.
#ifdef SHOW_DEBUGINFO
#ifdef SHOW_DEBUGINFO
debugPrint(F("T="));
debugPrintLn(temp);
debugPrint(F("P="));
debugPrintLn(pressure);
debugPrint(F("H="));
debugPrintLn(humidity);
debugPrint(F("B="));
debugPrintLn(batt);
debugPrint(F("BV="));
debugPrintLn(batvalue);
#endif
int t = (int)((temp + 40.0) * 10.0);
// t = t + 40; => t [-40..+85] => [0..125] => t = t * 10; => t [0..125] => [0..1250]
int p = (int)(pressure); // p [300..1100]
int h = (int)(humidity);
// Der Payload wird vorbereitet
unsigned char mydata[6];
mydata[0] = batvalue;
LMIC_setTxData2(1, mydata, sizeof(mydata), 0);
mydata[1] = h & 0xFF;
mydata[2] = t >> 8;
mydata[3] = t & 0xFF;
mydata[4] = p >> 8;
mydata[5] = p & 0xFF;
// Die Daten werden übertragen
// Wichtig ist an dieser Stelle das der Port 2 genutzt wird
LMIC_setTxData2(2, mydata, sizeof(mydata), 0);
debugPrintLn(F("PQ")); //Packet queued
}
// Next TX is scheduled after TX_COMPLETE event.
......@@ -287,7 +359,28 @@ void do_send(osjob_t* j)
void setup() {
Serial.begin(115200);
debugPrintLn(F("Starting"));
// Init BME208
if (!bme.begin())
{
debugPrintLn(F("No valid bme280 sensor!"));
delay(1000); // allow serial to send.
while (1)
{
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
Serial.println("Found BME280 sensor! Success.");
break;
case BME280::ChipModel_BMP280:
Serial.println("Found BMP280 sensor! No Humidity available.");
break;
default:
Serial.println("Found UNKNOWN sensor! Error!");
}
}
// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
......@@ -397,11 +490,13 @@ void loop()
LMIC_transmitted = 0;
LMIC_event_Timeout = 0;
//debugPrintLn(F("Going to sleep."));
//delay(1000); // allow serial to send.
/********************************************************************************
* Hier wird der Node in den Schlafmodus gelegt
*******************************************************************************/
#ifdef SHOW_DEBUGINFO
debugPrintLn(F("Going to sleep."));
#endif
if (interval > TRACKINGINTERVAL)
{
for (int i = 0; i < interval; i++)
......@@ -411,5 +506,7 @@ void loop()
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
}
//debugPrintLn("---");
#ifdef SHOW_DEBUGINFO
debugPrintLn("---");
#endif
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment