Wohnraumlüftung Arduino - MQTT - FHEM

Begonnen von Starsurfer, 05 November 2017, 17:14:21

Vorheriges Thema - Nächstes Thema

Starsurfer

Moin,
ich habe irgendwie gerade ein Brett vorm Kopf, vom vielen lesen und vielleicht könnt Ihr mir ja helfen.
Ich möchte eine Wohnraumlüftung mit FHEM und einen Arduino steuern, leider fehlt mir irgendwie gerade die Vorstellung wie ich das in FHEM anlege.

In FHEM ist MQTT mit mybroker eingerichtet.

Der Arduino soll 4 Temperaturen und die aktuelle Lüftergeschwindigkeit senden
Als Beispiel (Lüftergeschwindigkeit noch nicht fertig):
client.publish("zuHause/Arduino_1","online", true);
client.publish("/zuHause/Arduino_1/Lueftung/T1",TEMPChar);
client.publish("/zuHause/Arduino_1/Lueftung/T2",TEMPChar);
client.publish("/zuHause/Arduino_1/Lueftung/T3",TEMPChar);
client.publish("/zuHause/Arduino_1/Lueftung/T4",TEMPChar);


Wie lege ich das in FHEM an?


Mit FHEM möchte ich 3 Buttons haben, die es mir möglich macht die Lüfter in 3 Stufen zu steuern.
Button 1 soll ein PWM Signal von 75 setzten
Button 2 soll ein PWM Signal von 175 setzten
Button 3 soll ein PWM Signal von 75 setzten

Vielleiicht seid ihr ja so nett und helft mir auf die Sprünge.

Danke
FHEM Server: Fujitsu Esprimo q920 + LaCrosseGateway + HM-MOD-RPI-PCB WLAN + ConBee
HomeMatic HM-CC-RT-DN - Sonoff Tasmota
LaCrosse TX29DTH - Innr SP120 - Osram Smart+ Plug
Arduino Mega - MQTT - Pluggit 300
https://www.diy-robot-lawn-mower.com

eisman

#1
hi,

zum senden der daten:

define mqtt.RA01FE MQTT_BRIDGE RA01FE
attr mqtt.RA01FE IODev MQTT
attr mqtt.RA01FE publishReading_Fenster Haus/M8EGL/Wohnzimmer/Fenster
attr mqtt.RA01FE qos exactly-once
attr mqtt.RA01FE retain 1
attr mqtt.RA01FE room MQTT
attr mqtt.RA01FE stateFormat {ReadingsTimestamp($name,'transmission-state','')}


zum empfangen der Daten:

define Wetterstation MQTT_DEVICE
attr Wetterstation IODev MQTT
attr Wetterstation devStateStyle style=color:blue;;font-weight:bold;;text-align:right
attr Wetterstation room MQTT
attr Wetterstation stateFormat T: temperature H: humidity P: luftdruck W: wind
attr Wetterstation subscribeReading_hoflicht Haus/Wetter/Wetterstation/Hof/licht

ich habe mir dazu eine datei mit Fhem edit anglegt "MQTT.CFG"
und alles manuel eingetragen.

gruss
1x FHEM Debian, Homematic,ZigBee,FS20 / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian, Homematic,ZigBee         / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian,MQTT                               / 1X Raspberry, i2c,onewire,gpio
1x auf Windows 2012 Hyper-V-S

Starsurfer

Danke,
habe jetzt zumindest das Einstellen der Werte hinbekommen:
define myBroker MQTT 192.168.178.141:1883
attr myBroker room MQTT

define Lueftung MQTT_DEVICE
attr Lueftung IODev myBroker
attr Lueftung publishSet 75 175 254 zuHause/Arduino_1/Lueftung/
attr Lueftung room MQTT
attr Lueftung stateFormat transmission-state
FHEM Server: Fujitsu Esprimo q920 + LaCrosseGateway + HM-MOD-RPI-PCB WLAN + ConBee
HomeMatic HM-CC-RT-DN - Sonoff Tasmota
LaCrosse TX29DTH - Innr SP120 - Osram Smart+ Plug
Arduino Mega - MQTT - Pluggit 300
https://www.diy-robot-lawn-mower.com

eisman

1x FHEM Debian, Homematic,ZigBee,FS20 / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian, Homematic,ZigBee         / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian,MQTT                               / 1X Raspberry, i2c,onewire,gpio
1x auf Windows 2012 Hyper-V-S

eisman

Hi,

vielleicht hilft das: ungetestet
defmod doWert DOIF ([$SELF:wert] eq 0) (set xxx 0)\
DOELSEIF\
([$SELF:wert] eq 75) (set xxx 75)\
DOELSEIF\
([$SELF:wert] eq 175) (set xxx 175)
attr doWert cmdState 0|75|175
attr doWert readingList wert
attr doWert setList wert:,0,75,175
attr doWert webCmd wert:

setstate doWert 175
setstate doWert 2017-11-05 19:58:17 Device doWert
setstate doWert 2017-11-05 19:58:17 cmd 3
setstate doWert 2017-11-05 19:58:17 cmd_event doWert
setstate doWert 2017-11-05 19:58:17 cmd_nr 3
setstate doWert 2017-11-05 19:58:17 e_doWert_wert 175
setstate doWert 2017-11-05 19:58:17 error set xxx 175: Please define xxx first
setstate doWert 2017-11-05 19:58:17 state 175
setstate doWert 2017-11-05 19:58:17 wert 175


defmod mqtt.Luefter MQTT_BRIDGE doWert
attr mqtt.Luefter IODev MQTT
attr mqtt.Luefter publishReading_wert Haus/test/wert
attr mqtt.Luefter stateFormat transmission-state

setstate mqtt.Luefter outgoing publish sent
setstate mqtt.Luefter 2017-11-05 19:58:17 transmission-state outgoing publish sent


sendet über MQTT den wert 0,75,175,
muss aber noch angepasst werden!

ich würde es mit Firmata machen
1x FHEM Debian, Homematic,ZigBee,FS20 / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian, Homematic,ZigBee         / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian,MQTT                               / 1X Raspberry, i2c,onewire,gpio
1x auf Windows 2012 Hyper-V-S

Starsurfer

Habe es hinbekommen das FHEM an MQTT sendet, sieht dann so aus:
Message arrived [zuHause/Arduino_1/Lueftung/] 175

Allerdings habe ich keine Ahnung wie ich damit jetzt weitermache.
Ich müßte ja diesen Part ändern:
analogWrite(ENABLE_FAN1, FanSpeed);

FanSpeed sollte in diesem Beispiel dann 175 sein.

Um das zu ändern müßte ich die Funktion callback dementsprechend anpassen:
void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}


Nur finde ich keine Besipiele, wie das auszusehen hat.
FHEM Server: Fujitsu Esprimo q920 + LaCrosseGateway + HM-MOD-RPI-PCB WLAN + ConBee
HomeMatic HM-CC-RT-DN - Sonoff Tasmota
LaCrosse TX29DTH - Innr SP120 - Osram Smart+ Plug
Arduino Mega - MQTT - Pluggit 300
https://www.diy-robot-lawn-mower.com

eisman

hi,

da kann ich dir nichts zusagen, fange auch grade mit dem Arduino an
ich habe mir ConfigurableFirmata 2.06 geladen und mache alles aus
FHEM z.Z. per USB

kann also alle Analog,digital,PWM,i2c,SPI direct ansprechen

so ala, set PWM01 175 oder set DIG01 on
brauche in dem Fall keinen MQTT.

nachteil, ich warte seit 4Wochen auf das esp8266 esp-12e UART WiFi Wireless Shield

gruss
1x FHEM Debian, Homematic,ZigBee,FS20 / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian, Homematic,ZigBee         / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian,MQTT                               / 1X Raspberry, i2c,onewire,gpio
1x auf Windows 2012 Hyper-V-S

Starsurfer

Vielleicht findet sich ja noch jemand, der sich damit auskennt  :o
FHEM Server: Fujitsu Esprimo q920 + LaCrosseGateway + HM-MOD-RPI-PCB WLAN + ConBee
HomeMatic HM-CC-RT-DN - Sonoff Tasmota
LaCrosse TX29DTH - Innr SP120 - Osram Smart+ Plug
Arduino Mega - MQTT - Pluggit 300
https://www.diy-robot-lawn-mower.com

Starsurfer

So nach langem Basteln, habe ich erst einmal eine halbwegs funktionierende Lösung.
Was noch nicht geht: Temperatursensoren (noch nicht angeschlossen)
Die aktuelle Lüfterstufe in FHEM anzeigen lassen

Arduino Mega Script:
//TFT Pins
//CS=A3
//RS=A2
//WR=A1
//RD=A0
//RST=A4

//W5100 Shield
//50, 51, and 52 on the Mega. pin 10 is used to select the W5100 and pin 4 for the SD card

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>

MCUFRIEND_kbv tft;

#include <TimeLib.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <PubSubClient.h>
#include <SPI.h>

#include <OneWire.h>
#include <DallasTemperature.h>

// debug = 1 Schaltet die Serielle Ausgabe ein.
int debug = 1;

// Ethernet
byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0xFE, 0xAC }; //this is only valid for my Eth Shield, check yours at the back of Eth Shield
byte mask[] = { 255, 255, 255, 0 };
byte gw[] = { 192, 168, 178, 1 };
IPAddress ip(192, 168, 178, 79); //eine gültige IP Adresse für das eigene Netz
IPAddress server(192, 168, 178, 141); //die Adresse wo der eigene MQTT Broker drauf läuft

EthernetClient ethClient;
PubSubClient client(ethClient);

long lastReconnectAttempt = 0;

// NTP Servers:
IPAddress timeServer(192, 168, 178, 1);
static const char ntpServerName[] = "fritz.box";
const int timeZone = 1;     // Central European Time

EthernetUDP Udp;
unsigned int localPort = 8888;  // local port to listen for UDP packets

time_t getNtpTime();
void digitalClockDisplay();
void printDigits(int digits);
void sendNTPpacket(IPAddress &address);
// Ethernet Ende

// Data wire is plugged into pin 33 on the Arduino
#define ONE_WIRE_BUS 33
#define TEMPERATURE_PRECISION 9

OneWire oneWire(ONE_WIRE_BUS); // Einrichten des OneWire Bus um die Daten der Temperaturfühler abzurufen
DallasTemperature sensors(&oneWire); // Bindung der Sensoren an den OneWire Bus

int numberOfDevices; // Anzahl der gefundenen Sensoren
DeviceAddress TEMPDeviceAddress; // Variable zum zwischenspeichern der Adresse eines Sensors
unsigned long TEMPtimer;
unsigned long TEMPendTimer = 1000; // Schleifendurchläufe bis neue Abfrage startet
float TEMPSensor1 = 0;
float TEMPSensor2 = 0;
float TEMPSensor3 = 0;
float TEMPSensor4 = 0;
char TEMPChar[10]; // Hilsfvariable zu Konvertierung
String TEMPAsString; // Ausgelesene Temperatur als String
int TEMPDeviceCount = 0;

///////////////////Kann weg?
static char temperature[15];
float h = 0.0;
float h_alt = 0.0;
float t = 0.0;
float t_alt = 0.0;
unsigned long previousMillis = 0; //Zählervariable, zählt Millisekunden seit dem letzten Funktionsaufruf nach oben
const long interval = 120000; //120000 Millisekunden aka 120 Sekunden, das Interval wie oft der Sensor überhaupt benutzt wird
///////////////////////////////

//Ventilatoren
int Schrittweite = 20; // Variable für die Schrittweite pro Tasterdruck des PWM Wertes
int FanSpeed = 95; // PWM Startwert des Lüfters (ca.30%)
#define ENABLE_FAN1 44 //Lüfter Zuluft
#define ENABLE_FAN2 45 //Lüfter Abluft
#define FanPin1 39
#define FanPin2 37

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x7BEF

uint16_t ID;


// SETUP
// --------------------------------
void setup(void)
{
  Serial.begin(9600);
 
  start_tft();
  print_header();
  print_footer();
 
  Serial.println();
  Serial.println("Booting...");
  tft.setCursor(0, 30);
  tft.println("Booting...");
 
  // start the Ethernet connection and the server:
  client.setServer(server, 1883);
  client.setCallback(callback);
  Ethernet.begin(mac, ip, gw, gw, mask);
  delay(1500);
  Serial.println("Starte UDP Verbindung");
  tft.println(" ");
  tft.println("Starte UDP Verbindung");
  Udp.begin(localPort);
  delay(1500);
  Serial.println("Warte auf Zeitsynchronisation");
  tft.println("Warte auf Zeitsynchronisation");
  setSyncProvider(getNtpTime);
  setSyncInterval(1200000);
  time_t prevDisplay = 0; // when the digital clock was displayed
  lastReconnectAttempt = 0;

  Serial.print("Server Adresse: ");
  Serial.println(Ethernet.localIP());
  //tft.println(" ");
  tft.print("Server Adresse: ");
  tft.println(Ethernet.localIP());

  //Dallas Sensoren
  Serial.println("Suche Temperatur Sensoren...");
  //tft.println(" ");
  tft.println("Suche Temperatur Sensoren...");
 
  // Temperatur
  sensors.begin();
  TEMPDeviceCount = sensors.getDeviceCount();
  TEMPtimer = TEMPendTimer + 1;
  for(int i=0 ; i < TEMPDeviceCount; i++) {
    if(sensors.getAddress(TEMPDeviceAddress, i)) {
    sensors.setResolution(TEMPDeviceAddress, TEMPERATURE_PRECISION);
    }
  }

  if (debug == 1) {
  Serial.print("Temperatur Sensoren: ");
  Serial.println(TEMPDeviceCount, DEC);
  Serial.println("");
  Serial.println("Setup completed...");
  }
  tft.println("Setup completed...");

  delay (1000);
 
  //---Lüfter aktivieren
  tft.println("Teste Ventilatoren");
  pinMode(ENABLE_FAN1, OUTPUT);
  pinMode(ENABLE_FAN2, OUTPUT);
  pinMode(FanPin1, OUTPUT);
  pinMode(FanPin2, OUTPUT);
  digitalWrite(ENABLE_FAN1, HIGH); //enable on
  digitalWrite(ENABLE_FAN2, HIGH); //enable on
  /* Der Lüfter bekommt 10 Sekunde einen Startimpuls und wir dann gedrosselt.
      Das ist eine Sicherheitsmaßnahme, falls der Lüfter mit 30% nicht anläuft
  */
  analogWrite(ENABLE_FAN1, 255);
  analogWrite(ENABLE_FAN2, 255);
  // Lüfter auf eingestellte Geschwindigkeit zurückstellen
  delay (3000);
  analogWrite(ENABLE_FAN1, FanSpeed);
  analogWrite(ENABLE_FAN2, FanSpeed);
  client.publish("zuHause/Arduino_1/Lueftung/state", "1");
  //Serial.println(FanSpeed);
 
  tft.fillRect(0, 30, 480, 200, BLACK);

}// Setup

time_t prevDisplay = 0; // when the digital clock was displayed


// LOOP
// --------------------------------
void loop(void) {

   if (!client.connected()) {
  reconnect();
}

// Temperatur
// --------------------------------
if (TEMPtimer <= TEMPendTimer) TEMPtimer++;
else {
TEMPtimer = 0;
sensors.requestTemperatures();

  if ( TEMPDeviceCount == 0 ) {
    client.publish("zuHause/Arduino_1","Sensorfehler",true);
    if (debug == 1) {
    Serial.println("Keine Sensoren gefunden");
    }
  }

// TEMPSensor 1
  if ( TEMPDeviceCount == 1 ) {
    TEMPSensor1 = sensors.getTempCByIndex(0);
    dtostrf(TEMPSensor1,1,2,TEMPChar);
    client.publish("zuHause/Arduino_1","online", true);
    client.publish("zuHause/Arduino_1/Lueftung/Temp1",TEMPChar);
    if (debug == 1) {
    TEMPAsString = String(TEMPChar);
    Serial.println("Temp1: " + TEMPAsString);
    }
  } // TEMPSensor 1

// TEMPSensor 2
  if ( TEMPDeviceCount == 2 ) {
    TEMPSensor2 = sensors.getTempCByIndex(1);
    dtostrf(TEMPSensor2,1,2,TEMPChar);
    client.publish("zuHause/Arduino_1/Lueftung/Temp2",TEMPChar);
    if (debug == 1) {
    TEMPAsString = String(TEMPChar);
    Serial.println("Temp2: " + TEMPAsString);
    }
  } // TEMPSensor 2

// TEMPSensor 3
  if ( TEMPDeviceCount == 3 ) {
    TEMPSensor2 = sensors.getTempCByIndex(1);
    dtostrf(TEMPSensor3,1,2,TEMPChar);
    client.publish("zuHause/Arduino_1/Lueftung/Temp3",TEMPChar);
    if (debug == 1) {
    TEMPAsString = String(TEMPChar);
    Serial.println("Temp3: " + TEMPAsString);
    }
  } // TEMPSensor 3

// TEMPSensor 4
  if ( TEMPDeviceCount == 4 ) {
    TEMPSensor2 = sensors.getTempCByIndex(1);
    dtostrf(TEMPSensor4,1,2,TEMPChar);
    client.publish("zuHause/Arduino_1/Lueftung/Temp4",TEMPChar);
    if (debug == 1) {
    TEMPAsString = String(TEMPChar);
    Serial.println("Temp4: " + TEMPAsString);
    }
  } // TEMPSensor 3

} // else TEMPtimer

  sensor_layout();

  if (timeStatus() != timeNotSet) {
    if (now() != prevDisplay) { //update the display only if time has changed
      prevDisplay = now();
      digitalClockDisplay();
    }
  }

client.loop();
//Serial.print("Fan: " + FanSpeed);
//tft.print("Fan: " + FanSpeed);

}//Loop


void start_tft() {
  ID = tft.readID();  // you must detect the correct controller
  tft.begin(ID);      // everything will start working
  Serial.print("TFT controller: ");
  Serial.println(ID);
  tft.setRotation(1);
  tft.fillScreen(BLACK);
}

void print_header() {
  // *** oberer Rand ***************
  tft.fillRect(0, 0, 480, 20, RED);
  tft.setCursor(125, 0);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(" * Pluggit AP 300 * ");
  // *** oberer Rand ***************
  }


void print_footer() {
  // *** unterer Rand ***************
  tft.fillRect(0, 300, 480, 20, RED);
  tft.setCursor(130, 300);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print(" Version 1.0 BETA ");
  // *** unterer Rand ***************
  }

void sensor_layout() {

  tft.setCursor(20, 200);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Aussenluft: ");
  tft.print("25.3"); //DUMMY
  tft.println("\xF7");

  tft.setCursor(280, 200);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Fortluft: ");
  tft.print("25.3"); //DUMMY
  tft.print("\xF7");


  tft.setCursor(20, 250);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.println("Abluft:");

  tft.setCursor(280, 250);
  tft.setTextColor(CYAN);
  tft.setTextSize(2);
  tft.print("Zuluft: ");
  tft.print("25.3"); //DUMMY
  tft.print("\xF7");

}

void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
long now = millis();
if (now - lastReconnectAttempt > 5000) {
lastReconnectAttempt = now;
if (debug == 1) {
Serial.print("Attempting MQTT connection...");
}
// Attempt to connect
if (client.connect("Arduino_1", "zuHause/Arduino_1", 0, true, "offline")) {
  lastReconnectAttempt = 0;
  if (debug == 1) {
  Serial.println("connected");
  }
    // Once connected, publish an announcement...
    client.publish("zuHause/Arduino_1", "online", true);
    // ... and resubscribe
    client.subscribe("zuHause/Arduino_1/Lueftung/");
} else {
  if (debug == 1) {
  Serial.print("failed, rc=");
  Serial.print(client.state());
  Serial.println(" try again in 5 seconds");
  }
  // Wait 5 seconds before retrying
  delay(5000);
  }
}
}
}

//================================================================================================================
// Callback Funktion von MQTT. Die Funktion wird aufgerufen
// wenn ein Wert empfangen wurde.
//================================================================================================================
void callback(char* topic, byte* payload, unsigned int length) {

//convert topic to string to make it easier to work with
  String topicStr = topic;
  //EJ: Note:  the "topic" value gets overwritten everytime it receives confirmation (callback) message from MQTT

  //Print out some debugging info
  Serial.println("Callback update.");
  Serial.print("Topic: ");
  Serial.println(topicStr);

   if (topicStr == "zuHause/Arduino_1/Lueftung/")
    {

     //turn the switch on if the payload is '1' and publish to the MQTT server a confirmation message
     if(payload[0] == '0'){
         analogWrite(ENABLE_FAN1, 0);
         analogWrite(ENABLE_FAN2, 0);
       client.publish("zuHause/Arduino_1/Lueftung/state", "0");
       }

      //turn the switch off if the payload is '0' and publish to the MQTT server a confirmation message
     else if (payload[0] == '1'){
         analogWrite(ENABLE_FAN1, 75);
         analogWrite(ENABLE_FAN2, 75);
       client.publish("zuHause/Arduino_1/Lueftung/state", "1");
       }
     else if (payload[0] == '2'){
         analogWrite(ENABLE_FAN1, 175);
         analogWrite(ENABLE_FAN2, 175);
       client.publish("zuHause/Arduino_1/Lueftung/state", "2");
       }
     else if (payload[0] == '3'){
         analogWrite(ENABLE_FAN1, 255);
         analogWrite(ENABLE_FAN2, 255);
       client.publish("zuHause/Arduino_1/Lueftung/state", "3");
       }
     
     }
}


void digitalClockDisplay() {
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits) {
  // utility for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

/*-------- NTP code ----------*/

const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets

time_t getNtpTime()
{
  IPAddress ntpServerIP; // NTP server's ip address
  while (Udp.parsePacket() > 0) ; // discard any previously received packets
  Serial.println("Transmit NTP Request");
  sendNTPpacket(timeServer);
  uint32_t beginWait = millis();
  while (millis() - beginWait < 1500) {
    int size = Udp.parsePacket();
    if (size >= NTP_PACKET_SIZE) {
      Serial.println("Receive NTP Response");
      Udp.read(packetBuffer, NTP_PACKET_SIZE);  // read packet into the buffer
      unsigned long secsSince1900;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];
      return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
    }
  }
  Serial.println("No NTP Response :-(");
  return 0; // return 0 if unable to get the time
}

// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress &address)
{
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;
  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer, NTP_PACKET_SIZE);
  Udp.endPacket();
}


List Device:
Internals:
   IODev      myBroker
   NAME       Lueftung
   NR         265
   STATE      subscription acknowledged
   TYPE       MQTT_DEVICE
   READINGS:
     2017-11-08 16:04:37   state           2
     2017-11-08 16:13:17   transmission-state subscription acknowledged
   message_ids:
   publishSets:
     :
       topic      zuHause/Arduino_1/Lueftung/
       values:
         0
         1
         2
         3
   sets:
     0
     1
     2
     3
   subscribe:
     zuHause/Arduino_1/Lueftung/state
   subscribeExpr:
     ^zuHause\/Arduino_1\/Lueftung\/state$
   subscribeReadings:
     zuHause/Arduino_1/Lueftung/state:
       cmd
       name       state
Attributes:
   IODev      myBroker
   publishSet 0 1 2 3 zuHause/Arduino_1/Lueftung/
   room       MQTT
   stateFormat transmission-state
   subscribeReading_state zuHause/Arduino_1/Lueftung/state
FHEM Server: Fujitsu Esprimo q920 + LaCrosseGateway + HM-MOD-RPI-PCB WLAN + ConBee
HomeMatic HM-CC-RT-DN - Sonoff Tasmota
LaCrosse TX29DTH - Innr SP120 - Osram Smart+ Plug
Arduino Mega - MQTT - Pluggit 300
https://www.diy-robot-lawn-mower.com

SvenJust

Top! Ich lese mit Begeisterung mit...

VG Sven
FTUI, Raspberry PI/SSD, CUL CC1101, HMLAN, 10x HM-LC-Bl1PBU-FM, HM-LC-Sw4-WM (KWL Pluggit P300), HM-WDS30-OT2-SM (Sonnensensor), HM-Sec-SCo, LW-12 Wifi LED, CUL Selbstbau nanoCUL 433 (IT), Arduino (S0-Stromverbrauch), OW DS2480 (OWX_ASYNC) 8x DS18B20, MQTT (Fröling P4), MYSENSORS (Roto Rollläden)

eisman

Hi,

mal zur Info,

mit Firmata und FHEM,

dauer für das Projekt 15 min inclusive Einbindung von FRM

define <name> FRM {<device> | <port> [global]}
define <name> FRM_PWM <pin>

und DOIF oder dummy zur auswahl

gruss

1x FHEM Debian, Homematic,ZigBee,FS20 / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian, Homematic,ZigBee         / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian,MQTT                               / 1X Raspberry, i2c,onewire,gpio
1x auf Windows 2012 Hyper-V-S

Starsurfer

#11
Na super warum nehme ich dann MQTT?

Würde den der Arduino auch autark ohne FHEM laufen?
FHEM Server: Fujitsu Esprimo q920 + LaCrosseGateway + HM-MOD-RPI-PCB WLAN + ConBee
HomeMatic HM-CC-RT-DN - Sonoff Tasmota
LaCrosse TX29DTH - Innr SP120 - Osram Smart+ Plug
Arduino Mega - MQTT - Pluggit 300
https://www.diy-robot-lawn-mower.com

eisman

Hatte ich schon weiter oben geschrieben,

ich nutze den Arduino zur Zeit, für ein Anzeige Projekt,

i2c, Analogeingang, Digitaleingang, PWM für eine Integrierte Beleuchtung Geplant

Einstellung alle Räume über ein Tastenfeld, Überwachung der Türen, anzeige von Informationen (Temp,Fenster usw... )
und in Planung eine Nachtbeleuchtung Zeit und Helligkeit abhängig(5V LED Feld)

Wie auch schon gesagt CF nur version 2.06, 2.10 wird nicht unterstützt

gruss
1x FHEM Debian, Homematic,ZigBee,FS20 / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian, Homematic,ZigBee         / 1X Raspberry, ConBee / 5x ESP
1x FHEM Debian,MQTT                               / 1X Raspberry, i2c,onewire,gpio
1x auf Windows 2012 Hyper-V-S

Starsurfer

Na egal, jetzt ist es zu spät, ich mache mit MQTT weiter, auch wenn das nicht ganz so einfach ist.

So jetzt wird auch die Lüfter Stufe in FHEM angezeigt:
Internals:
   IODev      myBroker
   NAME       Lueftung
   NR         265
   STATE      3
   TYPE       MQTT_DEVICE
   READINGS:
     2017-11-08 17:06:56   state           3
     2017-11-08 17:06:56   transmission-state incoming publish received
   message_ids:
   publishSets:
     state:
       topic      zuHause/Arduino_1/Lueftung/
       values:
         0
         1
         2
         3
   sets:
     state      0,1,2,3
   subscribe:
     zuHause/Arduino_1/Lueftung/state
   subscribeExpr:
     ^zuHause\/Arduino_1\/Lueftung\/state$
   subscribeReadings:
     zuHause/Arduino_1/Lueftung/state:
       cmd
       name       state
Attributes:
   IODev      myBroker
   publishSet_state 0 1 2 3 zuHause/Arduino_1/Lueftung/
   room       MQTT
   stateFormat state
   subscribeReading_state zuHause/Arduino_1/Lueftung/state
FHEM Server: Fujitsu Esprimo q920 + LaCrosseGateway + HM-MOD-RPI-PCB WLAN + ConBee
HomeMatic HM-CC-RT-DN - Sonoff Tasmota
LaCrosse TX29DTH - Innr SP120 - Osram Smart+ Plug
Arduino Mega - MQTT - Pluggit 300
https://www.diy-robot-lawn-mower.com