Re: Systemvariablen auf CCU2 von NodeMCU
Verfasst: 01.05.2019, 21:56
int httpcode ist schon deklariert.
Nimm beim zweiten also das int weg
Nimm beim zweiten also das int weg
Heimautomation mit ELV HomeMatic und FHZ Funk-Hauszentralen
https://homematic-forum.de/forum/
Code: Alles auswählen
#include <Wire.h>
#include "TSIC.h"
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
TSIC TemperaturSensor(D3);
const byte Windsensorpin = D4;
// Variablen, um die Zeitverzögerung bei diversen Messungen zu Steuern
unsigned long previousMillisTemperatur = 0;
const long Temperaturmessintervall = 120000;
unsigned long previousMillisUebertragung = 0;
const long Uebertragungsintervall = 5000;
// Variablen für Temperaturmessung
uint16_t temperature = 0;
float Temperatur_C = 0;
// Variablen für Windmessung
volatile boolean TX20IncomingData = false;
unsigned char chk;
unsigned char sa,sb,sd,se;
unsigned int sc,sf, pin;
unsigned int Himmelsrichtung;
String tx20RawDataS = "";
String Windrichtung_Gartensensor;
const char* ssid="XXXXXXXX";
const char* password = "YYYYYYYY";
const char* HomematicIP = "192.168.0.11";
WiFiClient client;
HTTPClient http;
void setup() {
pinMode(Windsensorpin, INPUT);
attachInterrupt(digitalPinToInterrupt(Windsensorpin), isTX20Rising, RISING);
Serial.begin(115200);
delay(50);
Serial.println();
Serial.print("Wifi verbindet zu ");
Serial.println( ssid );
WiFi.begin(ssid,password);
Serial.println();
Serial.print("Verbinde");
while( WiFi.status() != WL_CONNECTED ){
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("Wifi Verbunden!");
Serial.print("NodeMCU IP Addresse : ");
Serial.println(WiFi.localIP() );
Serial.println();
if (client.connect(HomematicIP, 80)) {
Serial.println("Connected to Homematic!");
} else {
Serial.println("Connection to Homematic failed");
}
}
void loop() {
Temperaturmessung();
Windmessung();
unsigned long currentMillisUebertragung = millis();
if (currentMillisUebertragung - previousMillisUebertragung >= Uebertragungsintervall) {
previousMillisUebertragung = currentMillisUebertragung;
Uebertragung();
}
}
void Uebertragung() {
Himmelsrichtung = map(sb, 0, 16, 0, 360);
Serial.print("Himmelsrichtung: ");
Serial.print(Himmelsrichtung);
Serial.println();
int httpCode = http.GET();
String urlWindgeschwindigkeit = "http://" + String(HomematicIP) + ":80/x.exe?ret=dom.GetObject(\"Windgeschwindigkeit_Gartensensor\").State(" + sc + ")";
Serial.println(urlWindgeschwindigkeit);
http.begin(urlWindgeschwindigkeit);
httpCode = http.GET();
Serial.println("httpcode = " + String(httpCode));
// delay(2000);
String urlWindrichtung = "http://" + String(HomematicIP) + ":80/x.exe?ret=dom.GetObject(\"Windrichtung_Gartensensor\").State(" + Himmelsrichtung + ")";
Serial.println(urlWindrichtung);
http.begin(urlWindrichtung);
httpCode = http.GET();
Serial.println("httpcode = " + String(httpCode));
// delay(2000);
String urlTSIC306 = "http://" + String(HomematicIP) + ":80/x.exe?ret=dom.GetObject(\"Temperatur_Gartensensor_TSIC306\").State(" + Temperatur_C + ")";
Serial.println(urlTSIC306);
http.begin(urlTSIC306);
httpCode = http.GET();
Serial.println("httpcode = " + String(httpCode));
/*
String urlWindrichtung = "http://192.168.0.11/config/xmlapi/statechange.cgi?ise_id=12024&new_value=";
urlWindrichtung += String(Himmelsrichtung);
client.println(String("GET ") + urlWindrichtung + " HTTP/1.1\r\n" +
"Host: " + HomematicIP + "\r\n" +
"Connection: close\r\n\r\n");
*/
delay(2000);
}
void Temperaturmessung() {
unsigned long currentMillisTemperatur = millis();
if (currentMillisTemperatur - previousMillisTemperatur >= Temperaturmessintervall) {
previousMillisTemperatur = currentMillisTemperatur;
if (TemperaturSensor.getTemperature(&temperature)) {
Temperatur_C = TemperaturSensor.calc_Celsius(&temperature);
Serial.print("Temperatur: ");
Serial.println(Temperatur_C, 1);
Serial.println();
}
}
}
void isTX20Rising() {
if (!TX20IncomingData) {
TX20IncomingData = true;
}
}
void Windmessung() {
if (TX20IncomingData) {
char a[90];
boolean validData = readTX20();
Serial.println(tx20RawDataS);
sprintf(a, "ID: %d\t%d\n", sa, B00100);
Serial.write (a);
sprintf(a, "Wind direction: %d\t%d\n", sb, se);
Serial.write (a);
sprintf(a, "Wind speed: %d\t%d\n", sc, sf);
Serial.write (a);
sprintf(a, "Checksum: %d\t%d\n", sd, chk);
Serial.write (a);
// Windrichtung();
if (validData){
Serial.println(" :) OK :) OK :) OK :) OK");
} else {
Serial.println(" !!! ERROR !!! ERROR !!!");
}
Serial.println("");
}
}
boolean readTX20() {
int bitcount=0;
sa=sb=sd=se=0;
sc=0;sf=0;
tx20RawDataS = "";
for (bitcount=41; bitcount>0; bitcount--) {
pin = (digitalRead(Windsensorpin));
if (!pin) {
tx20RawDataS += "1";
} else {
tx20RawDataS += "0";
}
if ((bitcount==41-4) || (bitcount==41-8) || (bitcount==41-20) || (bitcount==41-24) || (bitcount==41-28)) {
tx20RawDataS += " ";
}
if (bitcount > 41-5){
// start, inverted
sa = (sa<<1)|(pin^1);
} else
if (bitcount > 41-5-4){
// wind dir, inverted
sb = sb>>1 | ((pin^1)<<3);
} else
if (bitcount > 41-5-4-12){
// windspeed, inverted
sc = sc>>1 | ((pin^1)<<11);
} else
if (bitcount > 41-5-4-12-4){
// checksum, inverted
sd = sd>>1 | ((pin^1)<<3);
} else
if (bitcount > 41-5-4-12-4-4){
// wind dir
se = se>>1 | (pin<<3);
} else {
// windspeed
sf = sf>>1 | (pin<<11);
}
delayMicroseconds(1220);
}
chk= ( sb + (sc&0xf) + ((sc>>4)&0xf) + ((sc>>8)&0xf) );chk&=0xf;
delayMicroseconds(2000); // just in case
TX20IncomingData = false;
if (sa==4 && sb==se && sc==sf && sd==chk){
return true;
} else {
return false;
}
}
Steht in der ESP8266HTTPClient.h:
Code: Alles auswählen
/// HTTP client errors
#define HTTPC_ERROR_CONNECTION_REFUSED (-1)
#define HTTPC_ERROR_SEND_HEADER_FAILED (-2)
#define HTTPC_ERROR_SEND_PAYLOAD_FAILED (-3)
#define HTTPC_ERROR_NOT_CONNECTED (-4)
#define HTTPC_ERROR_CONNECTION_LOST (-5)
#define HTTPC_ERROR_NO_STREAM (-6)
#define HTTPC_ERROR_NO_HTTP_SERVER (-7)
#define HTTPC_ERROR_TOO_LESS_RAM (-8)
#define HTTPC_ERROR_ENCODING (-9)
#define HTTPC_ERROR_STREAM_WRITE (-10)
#define HTTPC_ERROR_READ_TIMEOUT (-11)
Ich auch... man wächst mit seinem Ehrgeiz