I’m looking for an example sketch (Arduino IDE) which uses MQTT for sending data from ESP8266 to Pimatic plugin “pimatic-mqtt-simple”.
The idea is to use the ESP8266 for motion detection, but later on also for temperature sensor etc.
I was looking into ESPeasy, but I doubt if one of the MQTT protocolls from ESPeasy is supported by the pimatic plugin.
-
ESP8266 connect to pimatic-mqtt-simple
-
@cees said:
ESPeasy
It shouldn’t be too hard to alter the ESPEasy to be used with pimatic, I think the Domoticz MQTT protocol plugin is quite close to what pimatic expects. I know it has been asked at the ESPEasy forum a while ago, but the folks over there didn’t care too much to look into it. I think it shouldn’t be too hard to adapt either the ESPEasy software or the pimatic-simple-mqtt plugin.
On the other hand, adding a HTTP protocol for pimatic to ESPEasy would also be possible.The code for sending to Thingspeak for instance is quite similar to which is used in esp8266-pimatic-arduino:
https://github.com/ESP8266nu/ESPEasy/blob/master/_C004.ino:String postDataStr = SecuritySettings.ControllerPassword; // "0UDNN17RW6XAS2E5" // api key switch (event->sensorType) { case SENSOR_TYPE_SINGLE: // single value sensor, used for Dallas, BH1750, etc postDataStr += F("&field"); postDataStr += event->idx; postDataStr += "="; postDataStr += String(UserVar[event->BaseVarIndex]); break; case SENSOR_TYPE_TEMP_HUM: // dual value case SENSOR_TYPE_TEMP_BARO: postDataStr += F("&field"); postDataStr += event->idx; postDataStr += "="; postDataStr += String(UserVar[event->BaseVarIndex]); postDataStr += F("&field"); postDataStr += event->idx + 1; postDataStr += "="; postDataStr += String(UserVar[event->BaseVarIndex + 1]); break; case SENSOR_TYPE_SWITCH: break; } postDataStr += F("\r\n\r\n"); String postStr = F("POST /update HTTP/1.1\n"); postStr += F("Host: api.thingspeak.com\n"); postStr += F("Connection: close\n"); postStr += F("X-THINGSPEAKAPIKEY: "); postStr += SecuritySettings.ControllerPassword; postStr += "\n"; postStr += F("Content-Type: application/x-www-form-urlencoded\n"); postStr += F("Content-Length: "); postStr += postDataStr.length(); postStr += F("\n\n"); postStr += postDataStr; // This will send the request to the server client.print(postStr);
esp8266-pimatic-arduino:
//Send Humidity yourdata = "{\"type\": \"value\", \"valueOrExpression\": \"" + String(humidity) + "\"}"; client.print("PATCH /api/variables/"); client.print(espName); client.print("-hum HTTP/1.1\r\n"); client.print("Authorization: Basic "); client.print(authValEncoded); client.print("\r\n"); client.print("Host: " + host +"\r\n"); client.print("Content-Type:application/json\r\n"); client.print("Content-Length: "); client.print(yourdata.length()); client.print("\r\n\r\n"); client.print(yourdata); delay(500); //Send Temperature yourdata = "{\"type\": \"value\", \"valueOrExpression\": \"" + String(temperature) + "\"}"; client.print("PATCH /api/variables/"); client.print(espName); client.print("-tem HTTP/1.1\r\n"); client.print("Authorization: Basic "); client.print(authValEncoded); client.print("\r\n"); client.print("Host: " + host +"\r\n"); client.print("Content-Type:application/json\r\n"); client.print("Content-Length: "); client.print(yourdata.length()); client.print("\r\n\r\n"); client.print(yourdata);
-
I’ve used this one
https://github.com/tuanpmt/espduino
that sends data to mqtt, and the pimatic mqtt plugin shows it