AskSin++ Library

Begonnen von papa, 08 September 2016, 11:11:25

Vorheriges Thema - Nächstes Thema

papa

Zeigt denn das Beispiel immer Werte an ?
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

rvideobaer

Hallo,

Das habe ich leider noch nicht ausprobiert, aber das habe ich noch vor aber da muß der Computer die ganze Zeit laufen da ja kein Log geschrieben wird.

Gruß Rolf
Raspberry Pi 2, HM-Uart,1x HM-LC-Sw1PBU-FM, 1x HM-RC-2-PBU-FM,1x HM-LC-SW4-DR,1x HM-LC-Sw1-Pl-DN-R1,1x HM-TC-IT-WM-W-EU, 5x HM-CC-RT-DN und noch mehr

papa

Ich habe im Git einen V2 Branch eröffnet. Diese sollte jetzt für Eigenentwicklungen genutzt werden. Im Master werde ich wohl noch ein paar größere Umbauten machen. Dabei wird es sicherlich auch zu Inkompatibilitäten mit den existierenden Sketches kommen.
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

Wzut

Zitat von: rvideobaer am 31 August 2017, 18:46:59
Aber immer wieder zwischendurch ist die Temp 0 in unregelmäßigen abständen.
wundert mich nicht ... du gibst zwar ne Meldung auf der Seriellen aus das der Wert nicht gelesen werden konnte, reagierst aber nicht darauf und überschreibst trotzdem die alten Variablen. Ich würde das Messen so machen (ungetestet da ich hier keinen Compiler habe )
void measure ()
{
  DPRINT("Measure...\n");
  float t = dht.readTemperature();
  if  (isnan(t))
  {
    DPRINT("Failed to read Temperature\n");
    // warten und nochmal versuchen
    delay(5);
    t = dht.readTemperature();
    if  (isnan(t)) { DPRINT("No new Temperature\n"); }
    else { temp = t*10; }
   } else { temp = t*10; }
   
  float h = dht.readHumidity();
   if  (isnan(h))
   {
    DPRINT("Failed to read Humidity\n");
    // warten und nochmal versuchen
    delay(5);
    h = dht.readHumidity();
    if  (isnan(h)) { DPRINT("No new Humidity\n"); }
    else { humidity = h; }
   } else { humidity = h; }
}

D.h. lieber den alten Wert wieder schicken als einen falschen bzw. 0

Als Zweites suche mal im Netz nach der DHT lib. Es gibt davon verschiedene Versionen. Ich hatte irgendwann mal eine recht neue gefunden die intern andere Timingwerte benutzte.
Maintainer der Module: MAX, MPD, UbiquitiMP, UbiquitiOut, SIP, BEOK, readingsWatcher

rvideobaer

Hallo,

ich habe noch etwas mit der Firmware für den Temp.Sensor probiert. Wie gesagt ich habe von c++ so gut wie keine Ahnung. Ich bin auch auf ein paar Probleme gestoßen die ich mir nicht erklären kann.
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------

// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

// define all device properties
#define DEVICE_ID HMID(0x34,0x56,0x78)
#define DEVICE_SERIAL "papa111111"
#define DEVICE_MODEL  0x00,0x3d
#define DEVICE_FIRMWARE 0x10
#define DEVICE_TYPE DeviceType::THSensor
#define DEVICE_INFO 0x01,0x01,0x00

#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <TimerOne.h>
#include <LowPower.h>

#include <MultiChannelDevice.h>
#include <DHT.h>

// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8
#define DHTPIN 6     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

// number of available peers per channel
#define PEERS_PER_CHANNEL 6


// all library classes are placed in the namespace 'as'
using namespace as;

/**
* Configure the used hardware
*/
typedef AvrSPI<10,11,12,13> SPIType;
typedef Radio<SPIType,2> RadioType;
typedef StatusLed<4> LedType;
typedef AskSin<LedType,BatterySensor,RadioType> BaseHal;
class Hal : public BaseHal {
public:
  void init (const HMID& id) {
    BaseHal::init(id);
    // init real time clock - 1 tick per second
    rtc.init();
    // measure battery every 1h
    battery.init(60UL*60,rtc);
    battery.low(22);
    battery.critical(19);
  }

  bool runready () {
    return rtc.runready() || BaseHal::runready();
  }
} hal;

class WeatherEventMsg : public Message {
public:
  void init(uint8_t msgcnt,uint16_t temp,uint8_t humidity, bool batlow) {
    uint8_t t1 = (temp >> 8) & 0x7f;
    uint8_t t2 = temp & 0xff;
    if( batlow == true ) {
      t1 |= 0x80; // set bat low bit
    }
    Message::init(0xc,msgcnt,0x70,BIDI,t1,t2);
    pload[0] = humidity;
  }
};

class WeatherChannel : public Channel<Hal,List1,EmptyList,List4,PEERS_PER_CHANNEL>, public Alarm {

  WeatherEventMsg msg;
uint16_t        temp;
uint8_t         humidity;
  uint16_t        millis;

public:
  WeatherChannel () : Channel(), Alarm(5), temp(0), humidity(0), millis(0) {}
  virtual ~WeatherChannel () {}

  virtual void trigger (__attribute__ ((unused)) AlarmClock& clock) {
    // wait also for the millis
    if( millis != 0 ) {
      tick = millis2ticks(millis);
      millis = 0; // reset millis
      sysclock.add(*this); // millis with sysclock
    }
    else {
      uint8_t msgcnt = device().nextcount();
      measure();
      msg.init(msgcnt,temp,humidity,device().battery().low());
      device().sendPeerEvent(msg,*this);
//      device().send(msg,device().getMasterID());

      // reactivate for next measure
      HMID id;
      device().getDeviceID(id);
      uint32_t nextsend = delay1(id,msgcnt);
      tick = nextsend / 2000; // seconds to wait
      millis = nextsend % 1000; // millis to wait
      rtc.add(*this);
    }
  }

//   here we do the measurement
void measure () {
  Neumessen:
    DPRINT("Measure...\n");
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  delay(2000);
  if (isnan(h) || isnan(t)){
    DPRINT("Fehler Measure...neu\n");
  goto Neumessen;
  }
  temp = t*10;
  humidity = h;
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  }
   

  // here we calc when to send next value
  uint32_t delay1 (const HMID& id,uint8_t msgcnt) {
    uint32_t value = ((uint32_t)id) << 8 | msgcnt;
    value = (value * 1103515245 + 12345) >> 16;
    value = (value & 0xFF) + 480;
    value *= 250;

    DDEC(value / 1000);DPRINT(".");DDECLN(value % 1000);

    return value;
  }

  void setup(Device<Hal>* dev,uint8_t number,uint16_t addr) {
    Channel::setup(dev,number,addr);
    rtc.add(*this);
  Serial.begin(9600); //Serielle Verbindung starten
  dht.begin(); //DHT22 Sensor starten
  }

  uint8_t status () const {
    return 0;
  }

  uint8_t flags () const {
    return 0;
  }

};


typedef MultiChannelDevice<Hal,WeatherChannel,1> WeatherType;
WeatherType sdev(0x20);

ConfigButton<WeatherType> cfgBtn(sdev);

void setup () {
  DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
  sdev.init(hal);
  buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
}

void loop() {

  bool worked = hal.runready();
  bool poll = sdev.pollRadio();
  if( worked == false && poll == false ) {
    hal.activity.savePower<SleepRTC>(hal);
  }

}

Das ist die jetzige Variante die halbwegs Funktioniert. Bei der Messung habe ich nach der Auswertung und feststellen eines Fehlers einen Sprung zurück eingefügt. Da wird dann aber sehr oft hintereinander gemessen (10-12 mal) laut Beschreibung ist der Sensor aber nur alle 2 Sekunden bereit. Also wollte ich eine Verzögerung einbauen, aber der Name für die Funktion delay() wurde im code schon für irgend eine andere Sache benutzt so das ich immer nur einen Fehler bekam. Dann habe ich den Namen an den anderen Stellen im Code geändert so das er jetzt delay benutzt. Es scheint soweit alles zu gehen aber vielleicht habe ich auch etwas anders gestört ist mir aber noch nicht aufgefallen. Die Messungen werden jetzt noch max. 1-2 mal wiederholt. Über die Serielle Schnittstelle kann ich das gut beobachten.

Vielleicht könnte ja noch mal jemand schauen das ich nicht doch einen groben Schnitzer gemacht habe.

Gruß Rolf
Raspberry Pi 2, HM-Uart,1x HM-LC-Sw1PBU-FM, 1x HM-RC-2-PBU-FM,1x HM-LC-SW4-DR,1x HM-LC-Sw1-Pl-DN-R1,1x HM-TC-IT-WM-W-EU, 5x HM-CC-RT-DN und noch mehr

papa

#485
Damit machst DU das ganze Timing kaputt. Der HM-WDS10-TH-O sendet zu festen Zeitfenstern, welche durch die ID bestimmt werden. Wenn Du das nicht brauchst, dsa Du z.B kein Thermostat gepeert hast, kannst Du natürlich die Messung nach einer kurzen Zeit wiederholen. Ich würde es dann aber wie folgt machen:

measure() gibt TRUE oder FALSE zurück, je nachdem, ob es geklappt hat oder nicht. Bei TRUE wird die Nachricht geschickt und der Timer neu berechnet. Bei FALSE wird keine Nachricht geschickt und der Timer wird auf 2 Sekunden gesetzt.


virtual void trigger (__attribute__ ((unused)) AlarmClock& clock) {
    // wait also for the millis
    if( millis != 0 ) {
      tick = millis2ticks(millis);
      millis = 0; // reset millis
      sysclock.add(*this); // millis with sysclock
    }
    else {
      if( measure() == true ) {
        uint8_t msgcnt = device().nextcount();
        msg.init(msgcnt,temp,humidity,device().battery().low());
        device().sendPeerEvent(msg,*this);
//        device().send(msg,device().getMasterID());

        // reactivate for next measure
        HMID id;
        device().getDeviceID(id);
        uint32_t nextsend = delay(id,msgcnt);
        tick = nextsend / 1000; // seconds to wait
        millis = nextsend % 1000; // millis to wait
      }
      else {
        tick = 2; // 2 seconds
        millis = 0;
      }
      rtc.add(*this);
    }
  }

//   here we do the measurement
void measure () {
  DPRINT("Measure...\n");
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)){
    DPRINT("Fehler Measure...neu\n");
    return false;
  }
  temp = t*10;
  humidity = h;
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  return true;
  }
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

rvideobaer

Hallo,

leider bricht er mit Fehlermeldung ab:
invalid operands of types 'void' and 'bool' to binary 'operator=='
auf die Zeileif( measure() == true ) {bezogen.

Gruß Rolf
Raspberry Pi 2, HM-Uart,1x HM-LC-Sw1PBU-FM, 1x HM-RC-2-PBU-FM,1x HM-LC-SW4-DR,1x HM-LC-Sw1-Pl-DN-R1,1x HM-TC-IT-WM-W-EU, 5x HM-CC-RT-DN und noch mehr

papa

Ups


//   here we do the measurement
bool measure () {
  DPRINT("Measure...\n");
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

rvideobaer

Hallo,

leider nicht viel besser.

too many arguments to function 'void delay(long unsigned int)'

Gruß Rolf
Raspberry Pi 2, HM-Uart,1x HM-LC-Sw1PBU-FM, 1x HM-RC-2-PBU-FM,1x HM-LC-SW4-DR,1x HM-LC-Sw1-Pl-DN-R1,1x HM-TC-IT-WM-W-EU, 5x HM-CC-RT-DN und noch mehr

papa

Du hast mein delay umbenannt. Bitte zurück änderm.

Sei mir nicht böse, aber ich habe keine Zeit um bei trivialen C++ Fehlern zu helfen. Bitte verusche Dich in die Sprache einzuarbeiten. Es gibt genug Quellen.
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

rvideobaer

Ups,

da hast Du natürlich recht. Noch mal Danke.

Gruß Rolf
Raspberry Pi 2, HM-Uart,1x HM-LC-Sw1PBU-FM, 1x HM-RC-2-PBU-FM,1x HM-LC-SW4-DR,1x HM-LC-Sw1-Pl-DN-R1,1x HM-TC-IT-WM-W-EU, 5x HM-CC-RT-DN und noch mehr

papa

BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

rvideobaer

#492
Hallo,

Es geht, aber zufrieden bin ich noch nicht so richtig. Wenn der Fehler beim Datenholen auftritt dann sind meist 10 oder mehr Wiederholungen nötig. Auch Zweifel ich manchmal an den Daten, aber vielleicht liegt es auch an meinem Versuchsaufbau mit Steckbrett.

Gruß Rolf
Raspberry Pi 2, HM-Uart,1x HM-LC-Sw1PBU-FM, 1x HM-RC-2-PBU-FM,1x HM-LC-SW4-DR,1x HM-LC-Sw1-Pl-DN-R1,1x HM-TC-IT-WM-W-EU, 5x HM-CC-RT-DN und noch mehr

rvideobaer

Hallo,

ich habe versucht ein OTA-Firmware zu erstellen, aber leider bricht er immer ab.
/Users/rolf2/Downloads/ota/prepareforota.sh /Users/rolf2/Documents/Arduino/HM-WDS10-TH-O-DHT22-neu/HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.hex
++ date +%Y%m%d%H%M
+ QUAL=201709062105
+ FILE=/Users/rolf2/Documents/Arduino/HM-WDS10-TH-O-DHT22-neu/HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.hex
++ basename /Users/rolf2/Documents/Arduino/HM-WDS10-TH-O-DHT22-neu/HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.hex
+ NAME=HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.hex
++ basename /Users/rolf2/Documents/Arduino/HM-WDS10-TH-O-DHT22-neu/HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.hex .hex
+ BIN=HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.bin
++ basename /Users/rolf2/Documents/Arduino/HM-WDS10-TH-O-DHT22-neu/HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.hex .hex
+ EQ3=HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard_201709062105.eq3
+ cp /Users/rolf2/Documents/Arduino/HM-WDS10-TH-O-DHT22-neu/HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.hex HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.hex
+ ./srecord/srec_cat.exe HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.hex -intel -fill 0xFF 0x0000 0x6FFE -Cyclic_Redundancy_Check_16_Little_Endian 0x6FFE -o HM-WDS10-TH-O-DHT22-neu.ino.32PinBoard.bin -binary
/Users/rolf2/Downloads/ota/prepareforota.sh: line 10: ./srecord/srec_cat.exe: No such file or directory


funktioniert das auf dem Mac nicht, muss ich das unter windows ausführen?

Gruß Rolf
Raspberry Pi 2, HM-Uart,1x HM-LC-Sw1PBU-FM, 1x HM-RC-2-PBU-FM,1x HM-LC-SW4-DR,1x HM-LC-Sw1-Pl-DN-R1,1x HM-TC-IT-WM-W-EU, 5x HM-CC-RT-DN und noch mehr

papa

Ja - das "srec_cat" Tool wird benötigt. Für Windows ist es mit eingecheckt.

Du kannst aber auch das neue prepota.sh verwenden. Das läuft komplett in der bash - ist aber sehr langsam.

prepota.sh your.hex > your.eq3
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire