Dragino LoRa Shield - 868MHz v1.4 - Arduino UNO

Hallo Zusammen

Ich versuche Temperaturdaten vom Dragino Lora Shield 868 MHz v1.4 welches aufgesteckt auf dem Aruino UNO ist auf das TTN network zu senden.

Hardware: Dragino Lora Shield 868 MHz v1.4 / Arduino UNO
Ich kann den Code nicht kompilieren und die untenstehende Fehlremeldung kommt. Mir ist nun nicht klar was ich im Code ändern muss damit es schlussentlich funktioniert.

Folgender Code habe ich verwendet:

// 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

// Adaptions: Andreas Spiess

#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT_U.h>
#include <DHT.h>
#include <Adafruit_Sensor.h> 
#include <lmic.h>
#include <hal/hal.h>

#define ONE_WIRE_BUS_1 2

//#include <credentials.h>

OneWire bedroom_temp(ONE_WIRE_BUS_1);
DallasTemperature C(&bedroom_temp);
#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] = { XXXX, 0x2A, 0x1B, XXXX, 0x43, 0x27, XXXX, 0xFE, 0xD3, XXXX, 0xFE, XXXX, 0xD9, 0xBE, 0xA7, 0x95 };
static const u1_t APPSKEY[16] = { 0xB5, 0xEE, 0x7E, 0x01, xxxx, xxxx, 0x4D, xxxx, 0xEF, 0x3D, 0x54, xxxx, 0x1A, 0xF7, 0x3F, 0x24 };
static const u4_t DEVADDR = 0xxxxxxxxx;
#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;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;

// 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) {
        Serial.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[] = "Hallo zusammen";
    uint8_t message[2];
    message[0] = bedroom_temp;



    // Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
    } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, message, sizeof(message)-1, 0);
        Serial.println(F("Sending uplink packet..."));
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
    Serial.begin(115200);
    Serial.println(F("Starting..."));

    // 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_SF12,14);

    // Start job
    do_send(&sendjob);

    sensor_bedroom.begin();
    
}

void loop() {
    os_runloop_once();
    sensor_bedroom.requestTemperatures();
    float bedroom_temp = sensor_bedroom.getTempCByIndex(0);
//  Serial.print("bedroom_temp");
//  Serial.print(",");
//  Serial.print(bedroom_temp,2);
//      delay (2000);
    
}

Folgende Fehlermeldung kommt:

 /home/linus/Arduino/sketch_apr14a/sketch_apr14a.ino: In function 'void do_send(osjob_t*)':
sketch_apr14a:67:16: error: cannot convert 'OneWire' to 'uint8_t {aka unsigned char}' in assignment
     message[0] = bedroom_temp;
                ^
/home/linus/Arduino/sketch_apr14a/sketch_apr14a.ino: In function 'void setup()':
sketch_apr14a:107:5: error: 'sensor_bedroom' was not declared in this scope
     sensor_bedroom.begin();
     ^
/home/linus/Arduino/sketch_apr14a/sketch_apr14a.ino: In function 'void loop()':
sketch_apr14a:113:5: error: 'sensor_bedroom' was not declared in this scope
     sensor_bedroom.requestTemperatures();
     ^
Multiple libraries were found for "DallasTemperature.h"
 Used: /home/linus/Arduino/libraries/DallasTemperature
 Not used: /home/linus/Arduino/libraries/Arduino-Temperature-Control-Library-master
Using library OneWire-master at version 2.3.4 in folder: /home/linus/Arduino/libraries/OneWire-master 
Using library DallasTemperature at version 3.8.0 in folder: /home/linus/Arduino/libraries/DallasTemperature 
Using library DHT-sensor-library-master at version 1.3.1 in folder: /home/linus/Arduino/libraries/DHT-sensor-library-master 
Using library Adafruit_Sensor-master at version 1.0.2 in folder: /home/linus/Arduino/libraries/Adafruit_Sensor-master 
Using library arduino-lmic-master at version 1.5.0+arduino-2 in folder: /home/linus/Arduino/libraries/arduino-lmic-master 
Using library SPI at version 1.0 in folder: /opt/arduino-1.8.8/hardware/arduino/avr/libraries/SPI 
exit status 1
cannot convert 'OneWire' to 'uint8_t {aka unsigned char}' in assignment

naja sagt er doch:

sketch_apr14a:67:16: error: cannot convert 'OneWire' to 'uint8_t {aka unsigned char}' in assignment
message[0] = bedroom_temp;

er will also dein OneWire Objekt in das eine Byte stecken.

Du willst aber vermutlich da die Temperatur reinstopfen. Also musst du suchen wie deine Klasse die Temperatur in einem Byte zur Verfügung stellt. Oder vorher so casten, dass sie Platz hat.

Sidenote: Ist es gem. Spezifikation den DS jeden Loop-Durchlauf auszulesen? Gibt es da nicht etwas mit max alle n Sekunden?

Hi

Auf höchster Auflösung bekommt man eh nur alle ca. 750ms neue Messwerte - vorher bekommt man den Wert der alten Messung zurück, wenn die Messwerterfassung nicht blockierend geschrieben ist.
Wenn, blockiert der Sketch, bis die neue Messung fertig ist, somit kein alter Wert zum Auslesen da, man bekommt immer frische Werte - muß aber halt IMMER warten.

Bei Auslesen in jedem Durchlauf (oder sobald die Messung fertig ist), sollte man die Eigenerwärmung nicht außer Acht lassen.
Da Du wohl eine Luft-Temperatur erfassen willst, muß der Sensor Seine Temperatur an Diese abgeben - und selbst, wenn Er Das schafft, ist die Ihm umgebene Luft jetzt wärmer - so oder so bekommst Du 'mehr', als Da wirklich ist.
Wenn Du den DS18B20 als Anlegefühler z.B. an einem Cu-Heizungsrohr benutzt, kannst Du die Eigenerwärmung wohl komplett vernachlässigen, da dort neben besserer Wärmeleitung auch viel mehr Energie zu Deinem Sensor will.

bedroom_temp und sensor_bedroom - hier sollte der Unterschied klar ersichtlich sein.
Ersteres erstellst Du, Letzteres versuchst Du zu benutzen - gibt's aber gar nicht.

MfG

Danke für die raschen Rückmeldungen und die Hinweise. Habe den Code angepasst und sollte etwas besser verständlicher sein auch mit den Variablen. Sorry ich bin noch ein blutiger Anfänger

// 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

// Adaptions: Andreas Spiess


#include <lmic.h>
#include <hal/hal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//#include <MQ135.h>
//#include <credentials.h>

#define ONE_WIRE_BUS_1 2

OneWire oneWire_in(ONE_WIRE_BUS_1);
DallasTemperature sensor_inhouse(&oneWire_in);

#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] = { 0xE8, 0x2A, xxxx, 0x08, 0x43, 0x27, xxxx, 0xFE, 0xD3, 0xE6, 0xFE, 0xF2, 0xD9, 0xBE, 0xA7, 0x95 };
static const u1_t APPSKEY[16] = { 0xB5, 0xEE, 0x7E, xxxx 0x0F, 0x2B, 0x4D, 0xB6, 0xEF, 0x3D, xxxx, 0x53, 0x1A, 0xF7, 0x3F, 0x24 };
static const u4_t DEVADDR = 0xxxxxxxxx;
#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;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;

// 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) {
        Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
        // Schedule next transmission
        os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
    }
}

float sensor_value;
int16_t sensor_value_;

//MQ135 gassensor = analogRead(A0);

void do_send(osjob_t* j){
    // Payload to send (uplink)
    //static uint8_t message[] = "Hallo zusammen";
    uint8_t message[2];
    message[0] = sensor_value_ >> 8;
    message[1] = sensor_value_;


    // Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
    } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, message, sizeof(message)-1, 0);
        Serial.println(F("Sending uplink packet..."));
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
    Serial.begin(115200);
    Serial.println(F("Starting..."));

    // 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_SF12,14);

    // Start job
    do_send(&sendjob);

    sensor_inhouse.begin();
    
}

void loop() {
    os_runloop_once();

      sensor_value = sensor_inhouse.requestTemperatures();
      sensor_value_ = sensor_value;

//  Serial.print("Inhouse: ");
//  Serial.println(sensor_inhouse.getTempCByIndex(0));
//      delay (2000);
    
}

Nun kommt folgende Meldung beim kompilieren:

exit status 1
void value not ignored as it ought to be

Hi

Denke, da fehlt noch was an der Fehlermeldung, oder?
Schalte Mal ALLE Warnungen in den Einstellungen an - Datei - Voreinstellungen, beide Haken bei Ausführliche Meldungen.

MfG

Sorry

 /opt/arduino-1.8.8/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/opt/arduino-1.8.8/hardware/arduino/avr/cores/arduino -I/opt/arduino-1.8.8/hardware/arduino/avr/variants/standard -I/home/linus/Arduino/libraries/arduino-lmic-master/src -I/home/linus/Arduino/libraries/OneWire-master -I/home/linus/Arduino/libraries/DallasTemperature -I/opt/arduino-1.8.8/hardware/arduino/avr/libraries/SPI/src /tmp/arduino_build_181470/sketch/sketch_apr14a.ino.cpp -o /tmp/arduino_build_181470/sketch/sketch_apr14a.ino.cpp.o
/home/linus/Arduino/sketch_apr14a/sketch_apr14a.ino: In function 'void loop()':
sketch_apr14a:117:18: error: void value not ignored as it ought to be
     sensor_value = sensor_inhouse.requestTemperatures();
                  ^
Multiple libraries were found for "DallasTemperature.h"
 Used: /home/linus/Arduino/libraries/DallasTemperature
 Not used: /home/linus/Arduino/libraries/Arduino-Temperature-Control-Library-master
Using library arduino-lmic-master at version 1.5.0+arduino-2 in folder: /home/linus/Arduino/libraries/arduino-lmic-master 
Using library OneWire-master at version 2.3.4 in folder: /home/linus/Arduino/libraries/OneWire-master 
Using library DallasTemperature at version 3.8.0 in folder: /home/linus/Arduino/libraries/DallasTemperature 
Using library SPI at version 1.0 in folder: /opt/arduino-1.8.8/hardware/arduino/avr/libraries/SPI 
exit status 1
void value not ignored as it ought to be

Da hat der Kompiler Recht. Aus der DallasTemperature.h:

// sends command for all devices on the bus to perform a temperature conversion
void requestTemperatures(void);

Das holt keine Temperatur, sondern sagt: Fangt mal alle an zu messen.

Gruß Tommy

Hi

So, wie ich Das verstehe, hat
sensor_inhouse.requestTemperatures();
keinen Rückgabewert, und Diesen (nicht vorhandenen) Rückgabewert willst Du sensor_value zuweisen.
Diese Anweisung startet nur die Temperatur-Messung/Umwandlung.
Laut den Beispiel 'Single' für Uno & Co scheint Das blockierend zu sein, da im Beispiel direkt danach 'Done' im Terminal ausgegeben wird.

void loop(void)
{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  
  // It responds almost immediately. Let's print out the data
  printTemperature(insideThermometer); // Use a simple function to print out the data
}

Die Temperatur kommt erst mit Aufruf der Funktion printTemperature(deviceAddress), wo durch float tempC = sensors.getTempC(deviceAddress); der Wert in Celsius von der Lib zurück gegeben wird.

MfG

postmaster-ino:
Laut den Beispiel 'Single' für Uno & Co scheint Das >nicht< blockierend zu sein, da im Beispiel direkt danach 'Done' im Terminal ausgegeben wird.

Ich glaube, da fehlte ein nicht.

Gruß Tommy

Hallo Zusammen

Danke für Eure Hilfestellungen, bin schonmal weiter gekommen. Nun konnte ich den Code kompilieren, jedoch liefert mir der Serial Monitor den Wert -127.00 und auf dem TTN Network empfange ich 255. Was hier jemand weiter?

// 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

// Adaptions: Andreas Spiess


#include <lmic.h>
#include <hal/hal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//#include <MQ135.h>
//#include <credentials.h>

#define ONE_WIRE_BUS_1 2

OneWire oneWire_in(ONE_WIRE_BUS_1);
DallasTemperature sensor_inhouse(&oneWire_in);

#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] = { 0xE8, 0x2A, 0x1B, 0x08, 0x43, , 0x80, 0xFE, 0xD3,  0xFE, 0xF2, 0xD9, 0xBE, 0xA7, 0x95 };
static const u1_t APPSKEY[16] = { 0xB5, 0xEE, , 0x01, 0x0F, , 0x4D, 0xB6, 0xEF, 0x3D, 0x54, 0x53,  0xF7, 0x3F, 0x24 };
static const u4_t DEVADDR = ;
#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;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;

// 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) {
        Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
        // Schedule next transmission
        os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
    }
}

float sensor_value;
int16_t sensor_value_;

//MQ135 gassensor = analogRead(A0);

void do_send(osjob_t* j){
    // Payload to send (uplink)
    //static uint8_t message[] = "Hallo zusammen";
    uint8_t message[2];
    message[0] = sensor_value_ >> 8;
    message[1] = sensor_value_;


    // Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
    } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, message, sizeof(message)-1, 0);
        Serial.println(F("Sending uplink packet..."));
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
    Serial.begin(9600);
    Serial.println(F("Starting..."));

    // 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_SF12,14);

    // Start job
    do_send(&sendjob);

    sensor_inhouse.begin();
    
}

void loop() {
    os_runloop_once();

    sensor_inhouse.requestTemperatures();
    sensor_value = sensor_inhouse.getTempCByIndex(0);
    sensor_value_ = sensor_value;

    Serial.print("Inhouse: ");
    Serial.println(sensor_inhouse.getTempCByIndex(0));
    delay (2000);
    
}

Hi

Ich meinte wirklich blockierend, da ein DS18B20 bei maximaler Auflösung eben ~750ms braucht und in dem Beispielsketch NICHT gewartet wird, muß der Aufruf der Lib diese Zeit 'überbrücken'.

Wenn nicht, wird beim anschließendem Auslesen halt ein alter Wert zurück gegeben.

Die -127 stammen von der Lib und bedeuten: ungültige Messung.

Wie Das zu 255 wird, sehe ich aber nicht ... -1 wäre 255 (also alle Bits gesetzt, bei 8Bit).

MfG

Ok, dass schon dieser Aufruf blockiert war mir nicht bekannt. Es widerspricht auch Deiner Beschreibung

da im Beispiel direkt danach 'Done' im Terminal ausgegeben wird

Ich benutze immer

setWaitForConversion(false)

und steuere den Zeitablauf selbst über millis.

Gruß Tommy

Hi

Nein nein - Du verstehst mich miss :slight_smile:
Laut Sketch wird DIREKT 'Done' ausgegeben - und DAS sehe ich als Anzeichen dafür, daß der Aufruf so lange blockiert, bis die Lib damit halt fertig ist - sonst müsste hier ein Aufruf vorhanden sein, Der das Busy-Bit des Sensor ausliest - also erkennt, daß der Sensor fertig ist - und Das fehlt hier komplett.
Da im Anschluss vom 'Done' die Temperatur ausgelesen wird, muß dort eine 'neue' Temperatur vorhanden sein - und Die gibt's erst nach 750ms (in höchster Auflösung, gemessen hatte ich Mal knapp über 600ms).
Wenn das Beispiel nicht nur Augenwischerei ist, MUSS die Lib dort blockieren, sonst gibt's die 750ms einen alten Wert, dann irgendwann ist der Neue fertig und Den gibt's dann für die nächsten 750ms.

MfG

KISS: da die Temperature aber ohnehin nur alle 60 Sekunden gesendet werden soll, braucht man auch erst gar nicht versuchen, den alle 750ms zu lesen, bzw. ist nach 60 Sekunden eigentlich egal, ob dann der Wert schon 749ms alt ist. Bei SF12 wird das eh schon knapp mit 2 Byte alle 60 Sekunden oder?

Hallo besten dank für die Hilfestellungen.
Müsste ich nun vor dem auslesen des sensor wertes mit

    sensor_value = sensor_inhouse.getTempCByIndex(0);

Diesen teil noch einfügen:

setWaitForConversion(false)

Hallo kann mir jemand bei meinem ursprünglichen Problem weiterhelfen?

Was meinst Du, was wir alle bisher getan haben?

Gruß Tommy