Hi,
I started using pimatic a few weeks ago (not a professional programmer/it guy) and fell in love with it right away. Thanks to this forum, I got into homeduino combined with ESPimaticRF in order to send and receive 433MHz requests via wifi. So far, so good.
Unfortunately, ESPimaticRF does not support other sensors. I do need to use a DHT11 sensor, though, so I tried setting it up on a nodeMCU which simply sends data to my pimatic device.
This code is probably not written very well, but I am not fluent in C and had to copy and paste from what I could find in the example scripts.
First, I set up a DummyTemperatureSensor with ID schlafzimmer-dht1. This device should get its values via http GET. This does work on my local machine… BUT this machine also has the correct cookie. I used <IP>/api/device/schlafzimmer-dht1/changeHumidityTo?humidity=<value>
in order to successfully change the humidity value. Once I realized I needed to be logged in to post this, I used this sort of URL <username>:<password>@<IP>/api/device/schlafzimmer-dht1/changeHumidityTo?humidity=<value>
. This did work from my local machine using a private browser session, so I assume the syntax is correct.
Then I tried writing a program for the nodeMCU to transmit values. This is still messing around, for example, it does not even read DHT sensors values yet, rather just uses variables. I figured this was enough to test my script before adding support for DHT sensor. Anyway, this is the script:
#include <ESP8266WiFi.h>
const char* ssid = "<my ssid>";
const char* password = "<my wifi pw>";
const char* host = "<pimatic host>";
const char* myuser = "<pimatic username>";
const char* mypw = "<pimatic password>";
const char* urlHum = "/api/device/schlafzimmer-dht1/changeHumidityTo?humidity="; //URL to change Humidity
const char* urlTem = "/api/device/schlafzimmer-dht1/changeTemperatureTo?temperature="; //URL to change Temperature
void setup() {
Serial.begin(115200);
delay(10);
// connecting wifi
Serial.println();
Serial.println();
Serial.print("Verbinde mit ");
Serial.print(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() !=WL_CONNECTED) {
delay(500);
Serial.println(".");
}
Serial.println("");
Serial.println("Verbunden!");
Serial.println("Aktuelle IP: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("Verbunde mit ");
Serial.println(host);
// creating tcp connection with wifi client
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host,httpPort)) {
Serial.println("keine Verbindung");
return;
}
// using DUMMY VALUES to create appropriate URLs for pimatic API
int curHum = 70;
int curTem = 33;
String urlHum = "/api/device/schlafzimmer-dht1/changeHumidityTo?humidity=";
urlHum += curHum;
Serial.print("Frage an: ");
Serial.println(urlHum);
Serial.print("Frage an: ");
Serial.println(urlTem);
Code is just buggy from here on, so I did not post it. The correct URL for humidity seems to be created (serial monitor output /api/device/schlafzimmer-dht1/changeHumidityTo?humidity=70
, however, I cannot actually post the URL.
It should look like this http://myuser:mypw@host/api/device/schlafzimmer-dht1/changeHumidityTo?humidity=70 if I am not mistaken. At least I do get the desired effect (values changing in pimatic) when I directly post this URL in my browser.
This is a noobs early attempt to solve this problem. There is much work left, especially power saving mode in between sending values (I guess sending them every 15 minutes should even be enough) so power consumption can be minimized. But I can work on this once I got the initial code right.
Hopefully somebody can help me out. Thanks in advance for your support