Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
projekte:grossprojekte:lorawan:12_temp-feuchte [2020/03/11 23:06] – fablab_wiki | projekte:grossprojekte:lorawan:12_temp-feuchte [2022/12/14 12:48] (aktuell) – michael | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ===== 12 Temperatur - Luftfeuchte ===== | + | ===== 12. Temperatur - Luftfeuchte ===== |
\\ | \\ | ||
\\ | \\ | ||
Zeile 76: | Zeile 76: | ||
====Sketch==== | ====Sketch==== | ||
Was wäre eine Node ohne Programm (Sketch)? ([[projekte: | Was wäre eine Node ohne Programm (Sketch)? ([[projekte: | ||
- | Zur Verwendung kommt der LoRa-Universalsketch (diesmal mit Serial.print-Anweisungen, um den Ablauf im seriellen Monitor verfolgen zu können) mit Erweiterungen zum Auslesen des Sensors DHT22.\\ | + | Zur Verwendung kommt der LoRa-Universalsketch (von mir gekürzt und ohne die Serial.print-Anweisungen) mit Erweiterungen zum Auslesen des Sensors DHT22. |
- | Nartürlich muss der Sensor | + | Zum ersten Test wurden einige eigene Serial.print-Anweisungen verwendet. Sobald der Node funktionierte wurden sie deaktiviert.\\ |
+ | Nartürlich muss die Node vorher wieder im TTN-Netzwerk in seiner zugehörigen Applikation | ||
(Ich habe diese Daten im nachfolgenden Listing natürlich wieder unkenntlich gemacht)\\ | (Ich habe diese Daten im nachfolgenden Listing natürlich wieder unkenntlich gemacht)\\ | ||
+ | Der Sketch wurde mit der Bibliothek " | ||
\\ | \\ | ||
- | <code JavaScript [enable_line_numbers=" | + | <code JavaScript [enable_line_numbers=" |
/ | / | ||
| | ||
Zeile 117: | Zeile 119: | ||
#include < | #include < | ||
#include < | #include < | ||
+ | // | ||
//eigene Bibliotheken | //eigene Bibliotheken | ||
#include < | #include < | ||
// | // | ||
// eigene Defintitionen | // eigene Defintitionen | ||
- | |||
- | // | ||
//DHT22 | //DHT22 | ||
int pinDHT22 = 4; | int pinDHT22 = 4; | ||
SimpleDHT22 dht22(pinDHT22); | SimpleDHT22 dht22(pinDHT22); | ||
- | byte temperature = 0; | + | float temperature = 0; |
- | byte humidity = 0; | + | float humidity = 0; |
- | | + | // |
- | // Ende eigene Definitionen | + | |
// | // | ||
// Application EUI Reihenfolge LSB MSB | // Application EUI Reihenfolge LSB MSB | ||
- | static const u1_t PROGMEM APPEUI[8] = { 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x?? }; | + | static const u1_t PROGMEM APPEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
void os_getArtEui (u1_t* buf) { | void os_getArtEui (u1_t* buf) { | ||
memcpy_P(buf, | memcpy_P(buf, | ||
Zeile 138: | Zeile 138: | ||
//Device EUI Reihenfolge LSB MSB | //Device EUI Reihenfolge LSB MSB | ||
- | static const u1_t PROGMEM DEVEUI[8] = { 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x?? }; | + | static const u1_t PROGMEM DEVEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
void os_getDevEui (u1_t* buf) { | void os_getDevEui (u1_t* buf) { | ||
memcpy_P(buf, | memcpy_P(buf, | ||
Zeile 144: | Zeile 144: | ||
// Application Key Achtung: Reihenfolge MSB LSB | // Application Key Achtung: Reihenfolge MSB LSB | ||
- | static const u1_t PROGMEM APPKEY[16] = { 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x?? }; | + | static const u1_t PROGMEM APPKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
void os_getDevKey (u1_t* buf) { | void os_getDevKey (u1_t* buf) { | ||
memcpy_P(buf, | memcpy_P(buf, | ||
} | } | ||
- | static uint8_t payload[] = "Hi"; | + | static uint8_t payload[] = "XY"; |
- | // 2 Bytes werden gesendet | + | |
- | // | + | |
static osjob_t sendjob; | static osjob_t sendjob; | ||
// Schedule TX every this many seconds (might become longer due to duty | // Schedule TX every this many seconds (might become longer due to duty | ||
// cycle limitations). | // cycle limitations). | ||
- | const unsigned TX_INTERVAL = 1800; // 30 Minunten | + | const unsigned TX_INTERVAL = 1800; //30 Min |
- | // | ||
// Pin Mapping für Graduino LoRa Shield for Arduino | // Pin Mapping für Graduino LoRa Shield for Arduino | ||
const lmic_pinmap lmic_pins = { | const lmic_pinmap lmic_pins = { | ||
Zeile 193: | Zeile 190: | ||
void do_send(osjob_t* j) { | void do_send(osjob_t* j) { | ||
// Check if there is not a current TX/RX job running | // Check if there is not a current TX/RX job running | ||
- | if (LMIC.opmode & OP_TXRXPEND) | + | if (LMIC.opmode & OP_TXRXPEND) { |
- | | + | } else { |
- | } | + | |
- | | + | |
- | | + | |
// Eigene Sensoren | // Eigene Sensoren | ||
- | + | | |
- | byte temperature = 0; | + | humidity = 0; |
- | | + | |
int err = SimpleDHTErrSuccess; | int err = SimpleDHTErrSuccess; | ||
if ((err = dht22.read(& | if ((err = dht22.read(& | ||
{ | { | ||
- | Serial.print(" | + | |
- | return; | + | |
+ | temperature=0; | ||
+ | humidity=0; | ||
} | } | ||
- | Serial.print(" | + | |
- | Serial.print((byte)temperature); | + | |
- | Serial.print((byte)humidity); Serial.println(" | + | |
//DHT22 sampling rate is 0.5HZ. | //DHT22 sampling rate is 0.5HZ. | ||
delay(2500); | delay(2500); | ||
- | // die integerwerte | + | // die Integerwerte |
// d.h. Anzeige TTN 1. Byte 14 (Hex) ist 20 Grad Celsius | // d.h. Anzeige TTN 1. Byte 14 (Hex) ist 20 Grad Celsius | ||
// 2. Byte 38 (Hex) ist 56 % Rel H | // 2. Byte 38 (Hex) ist 56 % Rel H | ||
- | payload[0] = temperature; | + | payload[0] = int(temperature); |
- | payload[1] = humidity; | + | payload[1] = int(humidity); |
// Ende eigene Sensoren | // Ende eigene Sensoren | ||
- | // Prepare upstream data transmission at the next possible time. | + | |
- | | + | LMIC_setTxData2(1, |
} | } | ||
// Next TX is scheduled after TX_COMPLETE event. | // Next TX is scheduled after TX_COMPLETE event. | ||
Zeile 226: | Zeile 221: | ||
void setup() { | void setup() { | ||
- | | + | // Eigenes Setup |
- | Serial.begin(115200); | + | |
- | Serial.println(" | + | |
+ | // Ende eigenes Setup | ||
+ | // | ||
- | // | ||
- | #ifdef VCC_ENABLE | ||
- | // For Pinoccio Scout boards | ||
- | pinMode(VCC_ENABLE, | ||
- | digitalWrite(VCC_ENABLE, | ||
- | delay(1000); | ||
- | #endif | ||
// LMIC init | // LMIC init | ||
Zeile 242: | Zeile 232: | ||
// Reset the MAC state. Session and pending data transfers will be discarded. | // Reset the MAC state. Session and pending data transfers will be discarded. | ||
LMIC_reset(); | LMIC_reset(); | ||
- | LMIC_setClockError(MAX_CLOCK_ERROR * 2 / 100); | ||
- | LMIC_setupChannel(0, | ||
- | LMIC_setupChannel(1, | ||
- | LMIC_setupChannel(2, | ||
- | LMIC_setupChannel(3, | ||
- | LMIC_setupChannel(4, | ||
- | LMIC_setupChannel(5, | ||
- | LMIC_setupChannel(6, | ||
- | LMIC_setupChannel(7, | ||
- | LMIC_setupChannel(8, | ||
- | |||
- | LMIC_setLinkCheckMode(0); | ||
- | LMIC.dn2Dr = SF9; | ||
- | LMIC_setDrTxpow(DR_SF7, | ||
// Start job (sending automatically starts OTAA too) | // Start job (sending automatically starts OTAA too) | ||
do_send(& | do_send(& | ||
Zeile 261: | Zeile 237: | ||
void loop() { | void loop() { | ||
- | |||
- | | ||
os_runloop_once(); | os_runloop_once(); | ||
} | } | ||
Zeile 269: | Zeile 243: | ||
Was kommt hinzu: (Zeilenangaben in Klammern)\\ | Was kommt hinzu: (Zeilenangaben in Klammern)\\ | ||
\\ | \\ | ||
- | * (38) Bibliothek für den DHT22 (ist eine Einfachbibliothek, | + | * (39) Bibliothek für den DHT22 |
- | * (44-47) Datenpin, Initialisierung, | + | * (43-46) Datenpin |
- | * (69) Vorbelegung payload Variablen auf zwei Byte (wird später mit den Daten überschrieben) | + | * (110-131) Auslesen des Sensors mit Fehlerbehandlung, |
- | * (76) Sendeintervall in Sekunden | + | |
- | * (120-137) Auslesen des Sensors mit Fehlerbehandlung, | + | |
- | * (147-148) Ausgabe auf den seriellen Monitor - damit man weiß, dass es los geht | + | |
\\ | \\ | ||
\\ | \\ | ||
- | Stand: | + | Stand: |