Používám ESP8266 - tento:
https://cdn.itead.cc/media/catalog/prod ... 16_1_2.jpg (obrázek ESP8266)
Napadlo mě, že by to nestihlo zpracovat, tak sem tam dal delay(80000), ale pak se to jen přeruší a vypíše v dalším cyklu nesmysly.
Přidávám rozpracovaný program:
Kód: Vybrat vše
#include <Arduino.h>
#include <Wire.h>
#include <BH1750.h>
#include "Adafruit_SHT31.h"
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <SoftwareSerial.h>
BH1750 lightMeter;
Adafruit_SHT31 sht31 = Adafruit_SHT31();
#define BME280_ADRESA (0x76)
Adafruit_BME280 bme;
const byte rxPin = 10;
const byte txPin = 11;
SoftwareSerial ESP8266 (rxPin, txPin);
void setup(){
Serial.begin(9600);
ESP8266.begin(9600);
lightMeter.begin();
if (! sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr
Serial.println("SHT31 senzor nenalezen.");
while (1) delay(1);
}
if (!bme.begin(BME280_ADRESA)) {
Serial.println("BME280 senzor nenalezen.");
while (1);
}
}
void printResponse() {
while (ESP8266.available()) {
Serial.println(ESP8266.readStringUntil('\n'));
}
}
void loop() {
uint16_t lux = lightMeter.readLightLevel();
String lux_add = String(lux);
float t = sht31.readTemperature();
float h = sht31.readHumidity();
String teplota;
String teplota2;
int pozice_substr_teplota;
String vlhkost;
String vlhkost2;
int pozice_substr_vlhkost;
float tlak = bme.readPressure() / 100.0F;
String tlak_content = String(tlak);
int pozice_substr_tlak = tlak_content.indexOf('.') + 2;
String tlak_content_pridej = tlak_content.substring(0, pozice_substr_tlak);
if (! isnan(t)) {
teplota2 = String(t);
pozice_substr_teplota = teplota2.indexOf('.') + 2;
teplota = teplota2.substring(0, pozice_substr_teplota);
} else {
teplota = "none";
}
if (! isnan(h)) {
vlhkost2 = String(h);
pozice_substr_vlhkost = vlhkost2.indexOf('.') + 2;
vlhkost = vlhkost2.substring(0, pozice_substr_vlhkost);
} else {
vlhkost = "none";
}
String content_send = "&lang=cs&info=1*vt08LgA6kX*"+teplota+"*"+vlhkost+"*"+tlak_content_pridej+"*"+lux_add+"*none";
if(teplota != "") {
if(vlhkost != "") {
if(tlak_content_pridej != "") {
if(lux_add != "") {
//Serial.println(content_send);
ESP8266.println("AT+CIPSTART=\"TCP\",\"subdomena.domena.cz\",80");
delay(2000);
printResponse();
String cmd = "GET /index.php?s=data" + content_send + " HTTP/1.0\r\nHost: subdomena.domena.cz\r\n\r\n";
ESP8266.println("AT+CIPSEND=" + String(cmd.length() + 4));
delay(2000);
printResponse();
ESP8266.println(cmd);
delay(2000);
printResponse();
if (ESP8266.available())
Serial.write(ESP8266.read());
if (Serial.available())
ESP8266.write(Serial.read());
}}}}
delay(80000);
}
Kód: Vybrat vše
#include <SoftwareSerial.h>
.....
const byte rxPin = 10;
const byte txPin = 11;
SoftwareSerial ESP8266 (rxPin, txPin);
.....
void setup(){
Serial.begin(9600);
ESP8266.begin(9600);
....
}
void printResponse() {
while (ESP8266.available()) {
Serial.println(ESP8266.readStringUntil('\n'));
}
}
String content_send = "&lang=cs&info=1*vt08LgA6kX*"+teplota+"*"+vlhkost+"*"+tlak_content_pridej+"*"+lux_add+"*none";
if(teplota != "") {
if(vlhkost != "") {
if(tlak_content_pridej != "") {
if(lux_add != "") {
//Serial.println(content_send);
ESP8266.println("AT+CIPSTART=\"TCP\",\"subdomena.domena.cz\",80");
delay(2000);
printResponse();
String cmd = "GET /index.php?s=data" + content_send + " HTTP/1.0\r\nHost: subdomena.domena.cz\r\n\r\n";
ESP8266.println("AT+CIPSEND=" + String(cmd.length() + 4));
delay(2000);
printResponse();
ESP8266.println(cmd);
delay(2000);
printResponse();
if (ESP8266.available())
Serial.write(ESP8266.read());
if (Serial.available())
ESP8266.write(Serial.read());
}}}}
Výpis ze Sériového monitoru:
Kód: Vybrat vše
AT+CIPSTART="TCP","subdomena.domena.cz",80
CONNEC
AT+CIPSEND=128
OK
>
CLOSED
+CIPSTART="TCP","subdomena.domena.cz",80
AT+CIPSEND=128
link is not valid
ERROR
QzJ⸮ ⸮YXXlan⸮͙⸮R⸮⸮⸮⸮+%&⸮⸮34.2*973.9*256*none HTTP/1.0
Hos