Hello all.
Im not an script kiddo but i read a lot and don’t ask many questions.
But sometimes this copy paster kiddo needs some help.
I’m trying to push temperature data from a DS18b20 sensor by a wemos D1 mini to pimatic.
I can manage it for example with espeasy or by espimatic.
But my Wemos has to do a lot more and i would like to keep all te scripts in 1 file.
With copy and past i have created a file that is running without errors in the compiler.
But i have problems getting any data to pimatic.
I know the script looks like sht but i’m glad if i can get it running.
I’m standed in the section marked with
//Need help with this section*********
Hope anyone can or will help me
Snarf
// Import required libraries
#include "ESP8266WiFi.h"
#include <OneWire.h>
#include <DallasTemperature.h>
// Define pins (2 on Arduino)
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// WiFi parameters
const char* ssid = "MyNetWork";
const char* password = "Secret123";
// pimatic parameters
const char* PimaticUser = "admin";
const char* PimaticPassword = "adminorsomething";
const char* PimaticHost = "192.168.2.20";
const int PimaticPort = 8081;
void setup() {
// Start Serial
Serial.begin(115200);
delay(10);
sensors.begin();
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
Serial.print("Temperature for Device 1 is: ");
Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"?
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
Serial.print("Connecting to ");
Serial.println(PimaticHost);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(PimaticHost, PimaticPort)) {
Serial.println("connection failed");
return;
}
//******************Need help with this section****************************
// This will send the request to the server
// YWRtaW46WndlbWJAZA==
String yourdata;
yourdata = "{\"type\": \"value\", \"$esptemp\": \"" + String(123) + "\"}";
//yourdata = "{\"type\": \"value\", \"valueOrExpression\": \"" + String(h) + "\"}";
client.print("PATCH /api/variables/$esptemp");
client.print(" HTTP/1.1\r\n");
client.print("Authorization: Basic ");
client.print("YWRtaW46YWRtaW4=");
client.print("\r\n");
client.print("PimaticHost: mvegte.myqnapcloud.com\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);
//******************Need help with this section****************************
delay(500);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
// Repeat every 10 seconds
delay(10000);
}