Já jsem to upravil takto označeno ************* je to dobře? zatím nevím jak předávat SSID a PASSWORD ale to zatím neřeším
GPIO0 je na ESP-01 je při programování musí být na LOW ,jak zapojit tlačítko mám tam dát jako Pull UP odpor na zem nebo na 3V3 nebo to je zapnuto tímto pinMode(TRIGGER_PIN, INPUT_PULLUP)? díky
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <DNSServer.h>
//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);
*********** #define TRIGGER_PIN 0 //GPIO0 na ESP8266 ESP-01 ***************
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:
***** pinMode(TRIGGER_PIN, INPUT_PULLUP);********
***** if(digitalRead(TRIGGER_PIN) == LOW) {***********
***** WiFiManager wifiManager; ***********
***** wifiManager.startConfigPortal("ArduinoAP");*********
**** }***********
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í
}
}