From b4ae8dd2d7e7ba276b1ec78961f0f65ff723b3b3 Mon Sep 17 00:00:00 2001 From: Ralf Behrens Date: Tue, 11 Jan 2022 10:29:10 +0100 Subject: [PATCH 1/2] Sendeintervall 1 -> 10min --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5147126..93abb6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,7 +81,7 @@ static osjob_t sendjob; // Schedule TX every this many seconds (might become longer due to duty // cycle limitations). -const unsigned TX_INTERVAL = 60; +const unsigned TX_INTERVAL = 600; // Pin mapping // From df09c4b71f3306f06ba2e5d06dd71e9418fd995e Mon Sep 17 00:00:00 2001 From: Max Reble Date: Wed, 12 Jan 2022 13:11:26 +0100 Subject: [PATCH 2/2] tidy code --- src/MessenSensoren.cpp | 189 +++++++++++++++++++---------------------- src/main.cpp | 31 ++----- 2 files changed, 95 insertions(+), 125 deletions(-) diff --git a/src/MessenSensoren.cpp b/src/MessenSensoren.cpp index 9f699d5..142fc6c 100644 --- a/src/MessenSensoren.cpp +++ b/src/MessenSensoren.cpp @@ -1,11 +1,11 @@ // Sensoren lesen -#include +#include #include "MessenSensoren.h" #include -#include "myi2c.h" +#include "myI2C.h" #include "bme280.h" -#include "bh1750.h" +#include "BH1750.h" #include "hseSensorProtocol.h" #define I2C_POWER 5 // bei Feather M0 @@ -15,126 +15,113 @@ HseSP hse(2, 60); -void init_Messen(void) -{ -int i; +void init_Messen() { + int i; -Serial.println("PowerOn I2C"); + Serial.println("PowerOn I2C"); // I2C Power einschalten LoRa Transponder -pinMode(I2C_POWER,OUTPUT); -digitalWrite(I2C_POWER, HIGH); -delay(20); + pinMode(I2C_POWER, OUTPUT); + digitalWrite(I2C_POWER, HIGH); + delay(20); -Wire.begin(); + Wire.begin(); // Hardware detection, liste was angeschlossen ist -Serial.println("I2C Hardware detection"); - -if ( I2C_Test(BME280_ADR) != 0xFF ) - { - Set_I2C_Adresse(BME280_ADR); - i = I2C_read8(BME280_REGISTER_CHIPID); - Serial1.print(F("BMx280 Chip ID = 0x")); - Serial1.print(i,HEX); - if ( i== 0x58) Serial1.println(F(" = BMP280")); - if ( i== 0x60) Serial1.println(F(" = BME280")); - } - -if ( I2C_Test(0x77) != 0xFF ) - { - Serial.println("BMP180 gefunden"); - } - -if ( I2C_Test(0x38) != 0xFF ) - { - Serial.println(F("AHT10 gefunden")); - } + Serial.println("I2C Hardware detection"); + + if (I2C_Test(BME280_ADR) != 0xFF) { + Set_I2C_Adresse(BME280_ADR); + i = I2C_read8(BME280_REGISTER_CHIPID); + Serial1.print(F("BMx280 Chip ID = 0x")); + Serial1.print(i, HEX); + if (i == 0x58) Serial1.println(F(" = BMP280")); + if (i == 0x60) Serial1.println(F(" = BME280")); + } + + if (I2C_Test(0x77) != 0xFF) { + Serial.println("BMP180 gefunden"); + } + + if (I2C_Test(0x38) != 0xFF) { + Serial.println(F("AHT10 gefunden")); + } // such BH1730 -if ( I2C_Test(0x29) != 0xFF ) - { - Serial.println("BH1730 gefunden"); - } - + if (I2C_Test(0x29) != 0xFF) { + Serial.println("BH1730 gefunden"); + } + // such BH1750 -if ( I2C_Test(0x23) != 0xFF ) - { - Serial.println("BH1750 gefunden"); - BH1750_Init(); - } -Serial.println("ende"); + if (I2C_Test(0x23) != 0xFF) { + Serial.println("BH1750 gefunden"); + BH1750_Init(); + } + Serial.println("ende"); } //-------------------------- -void MessenSensoren(void) -{ -int i,status, error; -float t,p,h; -long lVisLux; - - -Set_I2C_Adresse(BME280_ADR); -i = I2C_read8(BME280_REGISTER_CHIPID); - -bme280_readCoefficients(); - -if ( i== 0x58) - { - I2C_write8(BME280_REGISTER_CONTROL, 0x3F); - delay(50); // gib ihm Zeit zum messen - } - -if ( i== 0x60) - { - //Set before CONTROL_meas (DS 5.4.3) - I2C_write8(BME280_REGISTER_CONTROLHUMID, 0x05); //16x oversampling - I2C_write8(BME280_REGISTER_CONTROL, 0xB7); // 16x ovesampling, normal mode - delay(100); // gib ihm Zeit zum messen - } +void MessenSensoren() { + int i; + float t, p, h; + unsigned int lVisLux; + + + Set_I2C_Adresse(BME280_ADR); + i = I2C_read8(BME280_REGISTER_CHIPID); + + bme280_readCoefficients(); + + if (i == 0x58) { + I2C_write8(BME280_REGISTER_CONTROL, 0x3F); + delay(50); // gib ihm Zeit zum messen + } + + if (i == 0x60) { + //Set before CONTROL_meas (DS 5.4.3) + I2C_write8(BME280_REGISTER_CONTROLHUMID, 0x05); //16x oversampling + I2C_write8(BME280_REGISTER_CONTROL, 0xB7); // 16x ovesampling, normal mode + delay(100); // gib ihm Zeit zum messen + } // 35ms reicht beim BMP280 // 75ms warten bis BME280 den Druck gemessen hat //---------------- - t = bme280_readTemperature(); - p = bme280_readPressure()/100.0; - h = bme280_readHumidity(); - I2C_write8(BME280_REGISTER_CONTROL, 0x3C); // Sleep Mode - - -// such BH1750 -if ( I2C_Test(0x23) != 0xFF ) - { - // BH1750 = HY30 Licht Sensor - BH1750_Init(); - lVisLux = BH1750_ReadLux(); - } - - if ( lVisLux > 65535) lVisLux = 654321; + t = bme280_readTemperature(); + p = bme280_readPressure() / 100.0f; + h = bme280_readHumidity(); + I2C_write8(BME280_REGISTER_CONTROL, 0x3C); // Sleep Mode -Serial.print(F("Temp = ")); -Serial.println(t); -Serial.print(F("Druck = ")); -Serial.println(p); -Serial.print(F("Feuchte = ")); -Serial.println(h); +// such BH1750 + if (I2C_Test(0x23) != 0xFF) { + // BH1750 = HY30 Licht Sensor + BH1750_Init(); + lVisLux = BH1750_ReadLux(); + } -Serial.print(F("Vis = ")); -Serial.println(lVisLux); + if (lVisLux > 65535) lVisLux = 654321; - hse.reset(); -//Ein Klimasensor hinzufügen - HseSP::ClimateSensor_t cs; - cs.Temperature = t; //°C - cs.Humidity = h; //% - cs.Pressure = p; //hPa - cs.Illuminance = lVisLux; //lux - hse.addClimateSensor(&cs); + Serial.print(F("Temp = ")); + Serial.println(t); + Serial.print(F("Druck = ")); + Serial.println(p); + Serial.print(F("Feuchte = ")); + Serial.println(h); -// hse.addVoltage(fUb/1000.0); // in Volt -// hse.addCounter(uiOnStd); // Zeit On + Serial.print(F("Vis = ")); + Serial.println(lVisLux); + hse.reset(); + //Ein Klimasensor hinzufügen + HseSP::ClimateSensor_t cs; + cs.Temperature = t; //°C + cs.Humidity = h; //% + cs.Pressure = p; //hPa + cs.Illuminance = lVisLux; //lux + hse.addClimateSensor(&cs); + // hse.addVoltage(fUb/1000.0); // in Volt + // hse.addCounter(uiOnStd); // Zeit On } diff --git a/src/main.cpp b/src/main.cpp index 93abb6d..ec3de8f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,20 +40,6 @@ #include "hseSensorProtocol.h" #include "MessenSensoren.h" -// -// For normal use, we require that you edit the sketch to replace FILLMEIN -// with values assigned by the TTN console. However, for regression tests, -// we want to be able to compile these scripts. The regression tests define -// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- -// working but innocuous value. -// -#ifdef COMPILE_REGRESSION_TEST -# define FILLMEIN 0 -#else -# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!" -# define FILLMEIN (##) -#endif - // This EUI must be in little-endian format, so least-significant-byte // first. When copying an EUI from ttnctl output, this means to reverse // the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, @@ -75,7 +61,6 @@ static const u1_t PROGMEM APPKEY[16] = {0xca, 0x96, 0x9a, 0x15, 0x76, 0x5d, 0xaf void os_getDevKey(u1_t *buf) { memcpy_P(buf, APPKEY, 16); } - static uint8_t mydata[] = "Hello, world!"; static osjob_t sendjob; @@ -143,15 +128,14 @@ void printHex2(unsigned v) { } - -void do_send(osjob_t *j) { +void do_send(__attribute__((unused)) osjob_t *j) { // 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. MessenSensoren(); - uint8_t* buffer = hse.getBuffer(); + uint8_t *buffer = hse.getBuffer(); int size = hse.getSize(); LMIC_setDrTxpow(DR_SF7, 10); @@ -226,8 +210,7 @@ void onEvent(ev_t ev) { case EV_REJOIN_FAILED: Serial.println(F("EV_REJOIN_FAILED")); break; - break; - case EV_TXCOMPLETE: + case EV_TXCOMPLETE: Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)")); if (LMIC.txrxFlags & TXRX_ACK) Serial.println(F("Received ack")); @@ -296,14 +279,14 @@ void setup() { Serial.begin(19200); Serial.println(F("Starting 1.02")); - #ifdef __SAMD21G18A__ +#ifdef __SAMD21G18A__ Serial.println(F("SAMD21G18A ARM Cortex-M0+ detected")); -#endif - #ifdef ARDUINO_SAMD_FEATHER_M0 +#endif +#ifdef ARDUINO_SAMD_FEATHER_M0 Serial.println(F("defined for Feather M0 Board")); #endif - init_Messen(); + init_Messen(); #ifdef CFG_eu868