<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ESP8266 Archive - Smartebude</title>
	<atom:link href="https://smartebude.de/category/esp8266/feed/" rel="self" type="application/rss+xml" />
	<link>https://smartebude.de/category/esp8266/</link>
	<description>Smart Home Deals, Homeassistant und ESP8266 Basteleien</description>
	<lastBuildDate>Sat, 12 Nov 2022 20:15:50 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://smartebude.de/wp-content/uploads/2023/01/cropped-smart_logo_favicon-32x32.png</url>
	<title>ESP8266 Archive - Smartebude</title>
	<link>https://smartebude.de/category/esp8266/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>DIY Windsensor mit MQTT mit Esp8266 für IObroker</title>
		<link>https://smartebude.de/diy-windsensor-mit-mqtt-mit-esp8266-fuer-iobroker/</link>
					<comments>https://smartebude.de/diy-windsensor-mit-mqtt-mit-esp8266-fuer-iobroker/#comments</comments>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Tue, 10 Sep 2019 07:57:44 +0000</pubDate>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[ESP8266]]></category>
		<category><![CDATA[IOBroker]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[diy]]></category>
		<category><![CDATA[esp8266]]></category>
		<category><![CDATA[iobroker]]></category>
		<category><![CDATA[mqtt]]></category>
		<category><![CDATA[sensor]]></category>
		<guid isPermaLink="false">https://derfrickler.de/?p=235</guid>

					<description><![CDATA[<p>Ein Windsensor für meine Haussteuerung steht schon lange auf meiner ToDo Liste. Diesen brauche ich vor allem als Sicherheitsfunktion für die automatische Steuerung der Raffstores &#8211; und aus Datensammelwut. Als Basis habe ich mir einen Ventus Ersatzsensor entkernt und dort einen ESP8266 + Arduino Mini Pro 3,3V untergebracht. Die Komponenten Folgende Komponenten habe ich verbaut: [...]</p>
<p>Der Beitrag <a href="https://smartebude.de/diy-windsensor-mit-mqtt-mit-esp8266-fuer-iobroker/">DIY Windsensor mit MQTT mit Esp8266 für IObroker</a> erschien zuerst auf <a href="https://smartebude.de">Smartebude</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="1024" height="768" src="https://derfrickler.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-1024x768.jpg" alt="" class="wp-image-238" srcset="https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-1024x768.jpg 1024w, https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-300x225.jpg 300w, https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-768x576.jpg 768w, https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-30x22.jpg 30w, https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-75x56.jpg 75w, https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-110x82.jpg 110w, https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-160x120.jpg 160w, https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-500x375.jpg 500w, https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-1536x1152.jpg 1536w, https://smartebude.de/wp-content/uploads/2019/09/MVIMG_20190909_075416-2048x1536.jpg 1600w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Ein Windsensor für meine Haussteuerung steht schon lange auf meiner ToDo Liste. Diesen brauche ich vor allem als Sicherheitsfunktion für die automatische Steuerung der Raffstores &#8211; und aus Datensammelwut. </p>



<p>Als Basis habe ich mir einen Ventus Ersatzsensor entkernt und dort einen ESP8266 + Arduino Mini Pro 3,3V untergebracht. </p>



<p></p>



<p><strong>Die Komponenten</strong></p>



<p>Folgende Komponenten habe ich verbaut: </p>



<ul class="wp-block-list">
<li>Ventus Ersatzwindmesser (<a href="https://www.reichelt.de/de/de/ersatz-windmesser-fuer-funkwetterstation-ventus-w132-p132595.html?r=1">link</a>)  ca. 23 € bei Reichelt .de</li>



<li>Arduino Pro 3,3V 8Mhz (<a href="https://amzn.to/2nCkogf">link</a>)  ca. 4 € bei Amazon.de</li>



<li>Wemos D1 Mini (<a href="https://amzn.to/2mUT4tb">link</a>) ca. 5 € bei Amazon.de</li>



<li>3 Volt Solarzelle (<a href="https://amzn.to/2mWt8xt">link</a>) für 8 € bei Amazon.de</li>



<li>100k Widerstand zur Spannungsmessung</li>
</ul>



<p>Macht insgesamt ca.  40 € für einen smarten Windsensor mit Batteriebetrieb. Deutlich Billiger als alle Modelle die auf dem Markt sind und auch etwas besser  zu befestigen als die Stab-Bauweise von Homematic. </p>



<p></p>



<p><strong>Warum 2 Boards?</strong><br>Für die Akkulaufzeit &#8211; den ESP8266 kann ich nicht mit einem externen Interrupt wecken ohne einen vollen Reboot zur durchlaufen. Der Arduino kann jedoch an 2 Interrupt Pins geweckt werden und anschließend wieder schlafen, ohne einen Reboot zu durchlaufen. </p>



<p>Der Ablauf ist eigentlich recht einfach, der Arduino zählt an PIN 2 alle Umdrehung des Windsensors und lauscht auf PIN3 ob ein Low vom Wemos gesetzt wird. Kommt das Signal auf PIN3 erfolgt eine Serielle Ausgabe des Aktuellen Windcounters. </p>



<p>Der Wemos Rebootet alle 30 Sekunden neu, liest den Serial Input und sendet ggf. Daten via MQTT an IObroker. Ansonsten sind beide Geräte im Deep Sleep und verbrauchen nur Minimal Strom.  </p>



<p>Der Ablauf nochmal grafisch dargestellt: </p>



<figure class="wp-block-image"><img decoding="async" width="908" height="684" src="https://derfrickler.de/wp-content/uploads/2019/09/New-Arduino-flowchart.png" alt="" class="wp-image-237" srcset="https://smartebude.de/wp-content/uploads/2019/09/New-Arduino-flowchart.png 908w, https://smartebude.de/wp-content/uploads/2019/09/New-Arduino-flowchart-300x226.png 300w, https://smartebude.de/wp-content/uploads/2019/09/New-Arduino-flowchart-768x579.png 768w, https://smartebude.de/wp-content/uploads/2019/09/New-Arduino-flowchart-30x23.png 30w, https://smartebude.de/wp-content/uploads/2019/09/New-Arduino-flowchart-75x56.png 75w, https://smartebude.de/wp-content/uploads/2019/09/New-Arduino-flowchart-110x83.png 110w, https://smartebude.de/wp-content/uploads/2019/09/New-Arduino-flowchart-160x121.png 160w, https://smartebude.de/wp-content/uploads/2019/09/New-Arduino-flowchart-500x377.png 500w" sizes="(max-width: 908px) 100vw, 908px" /></figure>



<p>Aktuell läuft das ganze noch im Testbetrieb, um zu sehen, wie sich die Batterielaufzeit verhält. Um möglichst lange Betriebszeiten zu erreichen werden 2 NiMH Akkus durch eine 3V Solarzelle geladen &#8211; ohne Laderegler. Den Laderegler halte ich für überflüssig, da NiMH Zellen ein überladen mit geringer Stärke gut verkraften. Ich habe die Akkus vorher einem Kapazitätstest unterzogen und werde im Frühjahr einen weiteren Test mache. </p>



<figure class="wp-block-image"><img decoding="async" src="blob:https://derfrickler.de/4cbf11e3-3098-4e7d-9795-242985a8109f" alt=""/><figcaption class="wp-element-caption">&#8222;Durchdachtes&#8220; Kabelmanagement im Prototyp</figcaption></figure>



<p><strong>Code Arduino Pro mini</strong></p>



<pre class="wp-block-code"><code lang="yaml" class="language-yaml">#include &lt;LowPower.h&gt;


#define WIND_INTERRUPT 0
#define ESP_INTERRUPT 1
#define WIND_INTERRUPT_PIN 3
#define ESP_INTERRUPT_PIN 2


volatile int pulses = 0;
volatile long last_interrupt_time = 0;
volatile int sendcheck = false;


void pulse() {

  unsigned long interrupt_time = millis();

  // If interrupts come faster than 200ms, assume it's a bounce and ignore
  if (interrupt_time - last_interrupt_time &gt; 10)
  {
    ++pulses;

  }
  last_interrupt_time = interrupt_time;
}


void ESP_awake() {
  sendcheck = true;
}


void sendWind() {

  int temppulse = pulses;

  delay(200);
  Serial.println("-");
  Serial.print("pulses:");
  Serial.println(temppulse);

  // gesendete vom Global Counter abziehen
  pulses -= temppulse;

}

void setup() {
  pinMode(WIND_INTERRUPT_PIN, INPUT_PULLUP);
  pinMode(ESP_INTERRUPT_PIN, INPUT);

  Serial.begin(9600);

  attachInterrupt(digitalPinToInterrupt(WIND_INTERRUPT_PIN), pulse, RISING);
  attachInterrupt(digitalPinToInterrupt(ESP_INTERRUPT_PIN), ESP_awake, FALLING);

}


void loop() {

  delay(100);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);


  // Wake up ab hier
  if (sendcheck) {
    sendcheck = false;
    sendWind();
  }
}</code></pre>



<p><strong>Code Wemos  / Esp8266</strong></p>



<pre class="wp-block-code"><code lang="yaml" class="language-yaml">
#include &lt;ESP8266WiFi.h&gt;
#include &lt;ESP8266HTTPClient.h&gt;
#include &lt;PubSubClient.h&gt;
#include &lt;RTCVars.h&gt;
RTCVars state; // create the state object

int reset_counter;
int program_step;
int sumwindcount;

unsigned int raw = 0;
float volt = 0.0;

WiFiClient espClient;
PubSubClient client(espClient);


const char* ssid = "****";
const char* password = "****";

const char* mqttServer = "192.168.****";
const int   mqttPort = 1886;
const char* mqttUser = "*****";
const char* mqttPassword = "*****";


int sleepTimeS = 30;
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine


void setup() {
  Serial.begin(9600);

  state.registerVar( &amp;reset_counter );
  state.registerVar( &amp;sumwindcount );

  if (state.loadFromRTC()) {
    reset_counter++;
  } else {
    reset_counter = 0;
    sumwindcount = 0;
    program_step = 0;
  }

  // Pin 4 Aktivieren / Deaktiveren &gt;&gt; Signal für Arudino Interrupt
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);
  delay(500);
  digitalWrite(4, LOW);

}


String getValue(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = { 0, -1 };
  int maxIndex = data.length() - 1;

  for (int i = 0; i &lt;= maxIndex &amp;&amp; found &lt;= index; i++) {
    if (data.charAt(i) == separator || i == maxIndex) {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i + 1 : i;
    }
  }
  return found &gt; index ? data.substring(strIndex[0], strIndex[1]) : "";
}



void senddata(int windspeed, int boe, float battery) {

  WiFi.begin(ssid, password);
  byte wifiCNT = 0;
  byte mqttCNT = 0;


  while (WiFi.status() != WL_CONNECTED  &amp;&amp; wifiCNT &lt; 10) {
    delay(500);
    wifiCNT++;
    Serial.println("Connecting to WiFi..");
  }

  Serial.println("Connected to the WiFi network");


  client.setServer(mqttServer, mqttPort);
  while (!client.connected() &amp;&amp; mqttCNT &lt; 10) {
    mqttCNT++;
    Serial.println("Connecting to MQTT...");
    if (client.connect("windsensor", mqttUser, mqttPassword )) {
      Serial.println("connected");
    } else {
      Serial.print("failed with state ");
      Serial.print(client.state());
      delay(200);

    }
  }


  if (windspeed != -1) {
    boolean rc = client.publish("windsensor/windspeed", String(windspeed).c_str());
  }

  if (battery != -1) {
    client.publish("windsensor/battery", String(battery).c_str());
  }
  if (boe != -1) {
    client.publish("windsensor/boe", String(boe).c_str());

  }

  delay(100);
}
void loop() {
  Serial.begin(9600);

  delay(100);
  String a;
  int aktwindcount = -1;

  while (Serial.available()) {
    Serial.println("wait for data");
    a = Serial.readString(); // read the incoming data as
    Serial.println(a);
    if (a.indexOf("pulses") &gt; 0) {
      a.replace("\n", "");
      a.replace("⸮-", "");
      a = getValue(a, ':', 1);

      Serial.println(a);
      aktwindcount = a.toInt();
      break;
    }

    delay(100);

  }


  if (aktwindcount &gt; 150) {
    senddata(-1, aktwindcount, -1);
  }

  // summe windcount erhöhen
  sumwindcount =  aktwindcount + sumwindcount;

  // aller 12 durchgänge senden oder wenn starker wind
  if (reset_counter &gt;= 12) {
    int raw = analogRead(A0);
    int windavg = sumwindcount / reset_counter;
    volt = raw / 1023.0;
    volt = volt * 4.2;


    senddata(windavg, -1, volt);
    reset_counter = 0;
    sumwindcount = 0;

  }

  state.saveToRTC();
  delay(100);
  ESP.deepSleep(29e6); // 20e6 is 20 microseconds


}




</code></pre>
<p>Der Beitrag <a href="https://smartebude.de/diy-windsensor-mit-mqtt-mit-esp8266-fuer-iobroker/">DIY Windsensor mit MQTT mit Esp8266 für IObroker</a> erschien zuerst auf <a href="https://smartebude.de">Smartebude</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://smartebude.de/diy-windsensor-mit-mqtt-mit-esp8266-fuer-iobroker/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
