Commit 1f26b3e1 authored by Frank Radzio 's avatar Frank Radzio

Vorlagen für die Nodes eingerichtet

parent fefce514
// MIT License
// https://github.com/gonzalocasas/arduino-uno-dragino-lorawan/blob/master/LICENSE
// Based on examples from https://github.com/matthijskooijman/arduino-lmic
// Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
//----------------------------------------------------------------
// GPS
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
// TTN
#include <lmic.h>
#include <hal/hal.h>
//#include <credentials.h>
static const int RXPin = 3, TXPin = 1; //GPS PIN
static const uint32_t GPSBaud = 9600; //GPS Baud
#ifdef CREDENTIALS
static const u1_t NWKSKEY[16] = NWKSKEY1;
static const u1_t APPSKEY[16] = APPSKEY1;
static const u4_t DEVADDR = DEVADDR1;
#else
static const u1_t NWKSKEY[16] = { ... }; // <- eigenen Wert setzen
static const u1_t APPSKEY[16] = { ... }; // <- eigenen Wert setzen
static const u4_t DEVADDR = 0x2601....; // <- DeviceAdress setzen
#endif
// These callbacks are only used in over-the-air activation, so they are
// left empty here (we cannot leave them out completely unless
// DISABLE_JOIN is set in config.h, otherwise the linker will complain).
void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }
static osjob_t sendjob;
uint8_t coords[9];
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 10;
// Pin mapping Dragino Shield
const lmic_pinmap lmic_pins = {
.nss = 10,
.rxtx = LMIC_UNUSED_PIN,
.rst = 9,
.dio = {2, 6, 7},
};
void onEvent (ev_t ev) {
if (ev == EV_TXCOMPLETE) {
//tft.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
}
}
void do_send(osjob_t* j){
// Payload to send (uplink)
// static uint8_t message[] = "hi";
get_coords();
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println("OP_TXRXPEND, not sending");
} else {
// Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, (uint8_t*) coords, sizeof(coords), 0);
Serial.println("Sending uplink packet...");
}
// Next TX is scheduled after TX_COMPLETE event.
}
void setup() {
Serial.begin(115200);
// TFT Setup
// tft.reset();
// uint16_t identifier = tft.readID();
// if (identifier == 0xEFEF) identifier = 0x9486;
// tft.begin(identifier);
// tft.fillScreen(0x0000);
// tft.setCursor(0, 0);
// tft.println("Hallo Tracking Node");
// Ende TFT
ss.begin(GPSBaud);
// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
// Set static session parameters.
LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
// Disable link check validation
LMIC_setLinkCheckMode(0);
// TTN uses SF9 for its RX2 window.
LMIC.dn2Dr = DR_SF9;
// Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
LMIC_setDrTxpow(DR_SF7,14);
// Start job
do_send(&sendjob);
}
void get_coords () {
// bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
float flat, flon, faltitudeGPS, fhdopGPS;
unsigned long age;
// tft.setCursor(0, 0);
// tft.println("Get GPS Coords");
smartDelay(1000);
Serial.println("Get Data");
flat = gps.location.lat();
Serial.println(flat);
flon = gps.location.lng();
Serial.println(flon);
faltitudeGPS = gps.altitude.meters();
Serial.println(faltitudeGPS);
fhdopGPS = gps.hdop.hdop();
Serial.println(fhdopGPS);
// gps.stats(&chars, &sentences, &failed);
int32_t lat = flat * 10000;
int32_t lon = flon * 10000;
int16_t altitudeGPS = faltitudeGPS * 100;
int8_t hdopGPS = fhdopGPS;
// Pad 2 int32_t to 6 8uint_t, big endian (24 bit each, having 11 meter precision)
coords[0] = lat;
coords[1] = lat >> 8;
coords[2] = lat >> 16;
coords[3] = lon;
coords[4] = lon >> 8;
coords[5] = lon >> 16;
coords[6] = altitudeGPS;
coords[7] = altitudeGPS >> 8;
coords[8] = hdopGPS;
}
// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
void loop() {
os_runloop_once();
}
# Basis der Wetternodes
Aus dieser Vorlage werden die Wetternodes entwickelt
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
BME280I2C Modes.ino
This code shows how to use predefined recommended settings from Bosch for
the BME280I2C environmental sensor.
GNU General Public License
Written: Dec 30 2015.
Last Updated: Sep 23 2017.
Connecting the BME280 Sensor:
Sensor -> Board
-----------------------------
Vin (Voltage In) -> 3.3V
Gnd (Ground) -> Gnd
SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
*/
#include <BME280I2C.h>
#include <Wire.h> // Needed for legacy versions of Arduino.
#define SERIAL_BAUD 115200
BME280I2C bme; // Default : forced mode, standby time = 1000 ms
// pressure ×1, temperature ×1, humidity ×1, filter off
/* Based on Bosch BME280I2C environmental sensor data sheet. */
//BME280I2C bme; // Weather Monitoring : forced mode, 1 sample/minute
// pressure ×1, temperature ×1, humidity ×1, filter off
// Current Consumption = 0.16 μA
// RMS Noise = 3.3 Pa/30 cm, 0.07 %RH
// Data Output Rate 1/60 Hz
//BME280I2C bme(1, 1, 0); // Humidity Sensing : forced mode, 1 sample/second
// pressure ×0, temperature ×1, humidity ×1, filter off
// Current Consumption = 2.9 μA
// RMS Noise = 0.07 %RH
// Data Output Rate = 1 Hz
//BME280I2C bme(2, 1, 5, 3, 0, 4); // Indoor Navigation : normal mode, standby time = 0.5ms
// pressure ×16, temperature ×2, humidity ×1, filter = x16
// Current Consumption = 633 μA
// RMS Noise = 0.2 Pa/1.7 cm
// Data Output Rate = 25Hz
// Filter Bandwidth = 0.53 Hz
// Response Time (75%) = 0.9 s
//BME280I2C bme(1, 0, 4, 3, 0, 4); // Gaming : normal mode, standby time = 0.5ms
// pressure ×4, temperature ×1, humidity ×0, filter = x16
// Current Consumption = 581 μA
// RMS Noise = 0.3 Pa/2.5 cm
// Data Output Rate = 83 Hz
// Filter Bandwidth = 1.75 Hz
// Response Time (75%) = 0.3 s
bool metric = false;
//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(SERIAL_BAUD);
while(!Serial) {} // Wait
while(!bme.begin())
{
Serial.println("Could not find BME280I2C sensor!");
delay(1000);
}
}
//////////////////////////////////////////////////////////////////
void loop()
{
printBME280Data(&Serial);
printBME280CalculatedData(&Serial);
delay(500);
}
//////////////////////////////////////////////////////////////////
void printBME280Data
(
Stream* client
)
{
float temp(NAN), hum(NAN), pres(NAN);
uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
bme.read(pres, temp, hum, pressureUnit, metric); // Parameters: (float& pressure, float& temp, float& humidity, bool hPa = true, bool celsius = false)
client->print("Temp: ");
client->print(temp);
client->print("°"+ String(metric ? 'C' :'F'));
client->print("\t\tHumidity: ");
client->print(hum);
client->print("% RH");
client->print("\t\tPressure: ");
client->print(pres);
client->print(" atm");
}
//////////////////////////////////////////////////////////////////
void printBME280CalculatedData
(
Stream* client
)
{
float altitude = bme.alt(metric);
client->print("\t\tAltitude: ");
client->print(altitude);
client->print((metric ? "m" : "ft"));
client->println();
}
/*
BME280 BRZO I2C Test.ino
This code shows how to record data from the BME280 environmental sensor
using I2C interface and https://github.com/pasko-zh/brzo_i2c library
on ESP8266.
This file is an example file, part of the Arduino BME280 library.
Copyright (C) 2016 Tyler Glenn
Forked by Alex Shavlovsky
to support https://github.com/pasko-zh/brzo_i2c library on ESP8266.
GNU General Public License
Written: Dec 30 2015.
Last Updated: Sep 23 2017.
Connecting the BME280 Sensor:
Sensor -> Board
-----------------------------
Vin (Voltage In) -> 3.3V
Gnd (Ground) -> Gnd
SDA (Serial Data) -> D2 on ESP8266
SCK (Serial Clock) -> D1 on ESP8266
*/
#include <BME280BRZO_I2C.h>
#define SERIAL_BAUD 115200
BME280BRZO_I2C bme; // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
bool metric = true;
//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(SERIAL_BAUD);
while(!Serial) {} // Wait
while(!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}
}
//////////////////////////////////////////////////////////////////
void loop()
{
printBME280Data(&Serial);
printBME280CalculatedData(&Serial);
delay(500);
}
//////////////////////////////////////////////////////////////////
void printBME280Data
(
Stream* client
)
{
float temp(NAN), hum(NAN), pres(NAN);
uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
client->print("Temp: ");
client->print(temp);
client->print("°"+ String(metric ? 'C' :'F'));
client->print("\t\tHumidity: ");
client->print(hum);
client->print("% RH");
client->print("\t\tPressure: ");
client->print(pres);
client->print(" atm");
}
//////////////////////////////////////////////////////////////////
void printBME280CalculatedData
(
Stream* client
)
{
float altitude = bme.alt(metric);
float dewPoint = bme.dew(metric);
client->print("\t\tAltitude: ");
client->print(altitude);
client->print((metric ? "m" : "ft"));
client->print("\t\tDew point: ");
client->print(dewPoint);
client->println("°"+ String(metric ? 'C' :'F'));
}
/*
BME280 I2C Test.ino
This code shows how to record data from the BME280 environmental sensor
using I2C interface. This file is an example file, part of the Arduino
BME280 library.
GNU General Public License
Written: Dec 30 2015.
Last Updated: Sep 19 2017.
Connecting the BME280 Sensor:
Sensor -> Board
-----------------------------
Vin (Voltage In) -> 3.3V
Gnd (Ground) -> Gnd
SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
*/
#include <BME280I2C.h>
#include <Wire.h> // Needed for legacy versions of Arduino.
#define SERIAL_BAUD 115200
BME280I2C bme; // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
bool metric = false;
//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(SERIAL_BAUD);
while(!Serial) {} // Wait
Wire.begin();
while(!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}
}
//////////////////////////////////////////////////////////////////
void loop()
{
printBME280Data(&Serial);
printBME280CalculatedData(&Serial);
delay(500);
}
//////////////////////////////////////////////////////////////////
void printBME280Data
(
Stream* client
)
{
float temp(NAN), hum(NAN), pres(NAN);
uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
client->print("Temp: ");
client->print(temp);
client->print("°"+ String(metric ? 'C' :'F'));
client->print("\t\tHumidity: ");
client->print(hum);
client->print("% RH");
client->print("\t\tPressure: ");
client->print(pres);
client->print(" atm");
}
//////////////////////////////////////////////////////////////////
void printBME280CalculatedData
(
Stream* client
)
{
float altitude = bme.alt(metric);
float dewPoint = bme.dew(metric);
client->print("\t\tAltitude: ");
client->print(altitude);
client->print((metric ? "m" : "ft"));
client->print("\t\tDew point: ");
client->print(dewPoint);
client->println("°"+ String(metric ? 'C' :'F'));
}
/*
BME280 Spi Sw Test.ino
This code shows how to record data from the BME280 environmental sensor
using Spi interface. This file is an example file, part of the Arduino
BME280 library.
GNU General Public License
Written: Dec 30 2015.
Last Updated: Sep 23 2017.
Connecting the BME280 Sensor:
Sensor -> Board
-----------------------------
Vin (Voltage In) -> 3.3V
Gnd (Ground) -> Gnd
SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
*/
#include <BME280SpiSw.h>
#define SERIAL_BAUD 115200
#define CHIP_SELECT_PIN 10
#define MOSI_PIN 11
#define MISO_PIN 12
#define SCK_PIN 13
BME280SpiSw bme(CHIP_SELECT_PIN, MOSI_PIN, MISO_PIN, SCK_PIN);
bool metric = false;
//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(SERIAL_BAUD);
while(!Serial) {} // Wait
while(!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}
}
//////////////////////////////////////////////////////////////////
void loop()
{
printBME280Data(&Serial);
printBME280CalculatedData(&Serial);
delay(1000);
}
//////////////////////////////////////////////////////////////////
void printBME280Data
(
Stream* client
)
{
float temp(NAN), hum(NAN), pres(NAN);
uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
client->print("Temp: ");
client->print(temp);
client->print("°"+ String(metric ? 'C' :'F'));
client->print("\t\tHumidity: ");
client->print(hum);
client->print("% RH");
client->print("\t\tPressure: ");
client->print(pres);
client->print(" atm");
}
//////////////////////////////////////////////////////////////////
void printBME280CalculatedData
(
Stream* client
)
{
float altitude = bme.alt(metric);
float dewPoint = bme.dew(metric);
client->print("\t\tAltitude: ");
client->print(altitude);
client->print((metric ? "m" : "ft"));
client->print("\t\tDew point: ");
client->print(dewPoint);
client->println("°"+ String(metric ? 'C' :'F'));
}
/*
BME280 Spi Test.ino
This code shows how to record data from the BME280 environmental sensor
using Spi interface. This file is an example file, part of the Arduino
BME280 library.
GNU General Public License
Written: Dec 30 2015.
Last Updated: Sep 23 2017.
Connecting the BME280 Sensor:
Sensor -> Board
-----------------------------
Vin (Voltage In) -> 3.3V
Gnd (Ground) -> Gnd
SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
*/
#include <SPI.h> // Needed for legacy versions of Arduino.
#include <BME280Spi.h>
#define SERIAL_BAUD 115200
#define DEVICE_PIN 10
BME280Spi bme(DEVICE_PIN); // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
bool metric = false;
//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(SERIAL_BAUD);
while(!Serial) {} // Wait
while(!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}
}
//////////////////////////////////////////////////////////////////
void loop()
{
printBME280Data(&Serial);
printBME280CalculatedData(&Serial);
delay(500);
}
//////////////////////////////////////////////////////////////////
void printBME280Data
(
Stream* client
)
{
float temp(NAN), hum(NAN), pres(NAN);
uint8_t pressureUnit(3); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
bme.read(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
client->print("Temp: ");
client->print(temp);
client->print("°"+ String(metric ? 'C' :'F'));
client->print("\t\tHumidity: ");
client->print(hum);
client->print("% RH");
client->print("\t\tPressure: ");