tak to máš textové podobě
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
WiFiManager wifiManager;
wifiManager.startConfigPortal("ArduinoAP");
//if you get here you have connected to the WiFi
Serial.println("connected...");
}
void loop() {
// put your main code here, to run repeatedly:
}
*******************************************************************************
//http://www.urel.feec.vutbr.cz/MPOA/2015/esp8266-ds18b20
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS); // Inicializace DS18B20 na pinu GPIO2
DallasTemperature DS18B20(&oneWire);
const char* ssid = ""; // Nastavení připojení k síti
const char* password = "";
const char* host = "api.thingspeak.com"; // Informace pro připojení k thingspeak.com
const char* APIkey = "";
bool scnd = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // Otevření komunikace po sériové lince
delay(10);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password); // Inicializace připojení k síti
while (WiFi.status() != WL_CONNECTED) { // Potvrzení připojení k síti
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
}
void loop() {
// put your main code here, to run repeatedly:
delay(30000); // Měření a odesílání teploty probíhá v intervalu cca 30s
float temp;
DS18B20.requestTemperatures(); // Získání informace o teplotě teploty
temp = DS18B20.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.println(temp);
char charVal[12];
dtostrf(temp, 8, 2, charVal); // Konverze vyčtené teploty do stringu
// (hodnota, počet míst, počet desetinných míst,
// umístění stringu)
if(scnd){
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
String url = "/update?key="; // Vytvoření URL pro odeslání informace o teplotě
url += APIkey;
url += "&field1=";
url += charVal;
Serial.print("Requesting URL: ");
Serial.println(url);
// Odeslání požadavku na server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);
Serial.println();
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line); // tisk informací přijatých ze serveru
}
Serial.println();
Serial.println("connection completed"); // potvrzení ukončení odesílání
Serial.println();
Serial.println();
}
else
{
Serial.println("uncorrect first temperatue");
Serial.println(); // Ošetření nesprávnosti první změřené hodnoty po připojení
scnd=true; // k napájení
}
}
díky za pomoc