Warning: htmlspecialchars(): charset `utf8' not supported, assuming utf-8 in /usr/local/apache2/htdocs/wp-trust.tomaspexa.cz/wp-content/plugins/jetpack/modules/carousel/jetpack-carousel.php on line 506

Warning: htmlspecialchars(): charset `utf8' not supported, assuming utf-8 in /usr/local/apache2/htdocs/wp-trust.tomaspexa.cz/wp-content/plugins/jetpack/modules/carousel/jetpack-carousel.php on line 507

Warning: htmlspecialchars(): charset `utf8' not supported, assuming utf-8 in /usr/local/apache2/htdocs/wp-trust.tomaspexa.cz/wp-content/plugins/jetpack/modules/carousel/jetpack-carousel.php on line 506

Warning: htmlspecialchars(): charset `utf8' not supported, assuming utf-8 in /usr/local/apache2/htdocs/wp-trust.tomaspexa.cz/wp-content/plugins/jetpack/modules/carousel/jetpack-carousel.php on line 507

Warning: htmlspecialchars(): charset `utf8' not supported, assuming utf-8 in /usr/local/apache2/htdocs/wp-trust.tomaspexa.cz/wp-content/plugins/jetpack/modules/carousel/jetpack-carousel.php on line 506

Warning: htmlspecialchars(): charset `utf8' not supported, assuming utf-8 in /usr/local/apache2/htdocs/wp-trust.tomaspexa.cz/wp-content/plugins/jetpack/modules/carousel/jetpack-carousel.php on line 507

Wifi modul ESP 8266

testuji měření teploty a zasílání hodnot na server

temp-chart.

  • SoC – Espressif Systems ESP8266 32-bit RISC processor with 802.11 b/g/n support(32-pin QFN package),
  • Wi-Fi – 802.112 b/g/n with WEP, TKIP, AES, and WAPI engines, Wi-Fi direct (P2P), and soft-AP. On-board antenna and u.FL connector

 

MOD-WIFI-ESP8266-DEV olimex-nepaj-pole

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
//#include <WifiConfig.h>

// EasyIoT server definitions
#define EIOT_USERNAME    ""
#define EIOT_PASSWORD    ""
#define EIOT_IP_ADDRESS  "xxx.xxx.xxx.xxx"
#define EIOT_PORT        80
#define EIOT_NODE        "doma"

#define REPORT_INTERVAL 60 // in sec
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 12
#define TEMPERATURE_PRECISION 10
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer, outsideThermometer;

ESP8266WebServer wwwserver(80); // webovy server - pouzity je jak pro nastaveni ESP modulu pomoci WifiConfig, tak pro praci aplikace
String content;

//WifiConfig wifi; // konfigurace ESP modulu

const char *ssid = "";
const char *password = "";
float oldTemp,humidity,temp_f;
float g_teplota[4];
char dAddress[16];
int Index = 0;
const int sleepTimeS = 30;
int vcc;
int deepsleep = 4 * 60 * 1000 * 1000;


// funkce na zobrazeni uvodni stranky
static void handleRoot(void)
{

  content = F("<!DOCTYPE HTML>\n<html>Hello world from ESP8266");
  content += F("<p>");
  content += F("</html>");

  wwwserver.send(200, F("text/html"), content);
}

void setup()
{
        Serial.begin(115200);
        Serial.println("start\n");
        EEPROM.begin(512); // zahajujeme praci s EEPROM
         delay(5000); 
       //WiFi.softAP(ssid);
       WiFi.begin(ssid, password);
       sensors.begin();
        // locate devices on the bus
        Serial.print("Locating devices...");
        Serial.print("Found ");
        Serial.print(sensors.getDeviceCount(), DEC);
        Serial.println(" devices.");
          Serial.print("Device 0 Address: ");
            // report parasite power requirements
        Serial.print("Parasite power is: "); 
        if (sensors.isParasitePowerMode()) Serial.println("ON");
        else Serial.println("OFF");
          sensors.getAddress(insideThermometer, 0);
          sensors.getAddress(outsideThermometer, 1);
          sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
          sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
        Serial.println();
        pinMode(5, OUTPUT);

 
}
void client (int) {
  wwwserver.handleClient();
}
void loop()
{
        vcc = ESP.getVcc();
        Serial.println(vcc);
          // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");
  // print the device information
  printData(insideThermometer);
  printData(outsideThermometer);
    ctiTeplotu(0);
    ctiTeplotu(1);
       sendTeperature();
        blink();
         ESP.deepSleep(deepsleep, WAKE_RF_DEFAULT); 
         delay(1000); 

}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    // zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");
  Serial.print(tempC);
   //Serial.println(g_teplota[idx]);
}
void ctiTeplotu(int idx) {
    sensors.requestTemperatures();
    g_teplota[idx] =  sensors.getTempCByIndex(idx);
    g_teplota[idx] =  sensors.getTempCByIndex(idx);
    Serial.println(g_teplota[idx]);
    
  }
 void printData(DeviceAddress deviceAddress)
{
  Serial.print("Device Address: ");
  printAddress(deviceAddress);
  Serial.print(" ");
  printTemperature(deviceAddress);
  Serial.println();
}

 // funkce odeslat teplotu klientovi
void temp () {
    String message = "Aktualni teplota\n\n";
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
   //"Requesting temperatures...";
  //message += "Temperature for the device 1 (index 0) is: ";
  //message += g_teplota;
  wwwserver.send ( 200, "text/plain", message );
}

  void blink (){
    digitalWrite(5,!digitalRead(5));   // turn the LED on (HIGH is the voltage level)
  }
  void sendTeperature()
{  
  int x=0;
   WiFiClient client;
   while(!client.connect(EIOT_IP_ADDRESS, EIOT_PORT)) {
      Serial.println("connection failed");
         delay(5000);
         if ( x > 5 ) {
            return;
         } 
         x++;
  } // konec while
   
  String url = "";
  url += "/IoT/index.php?&Virtual="+ String(EIOT_NODE) + "&ControlLevel[0]="+String(g_teplota[0])+"&ControlLevel[1]="+String(g_teplota[1]); // generate EasIoT server node URL

  Serial.print("GET data to URL: ");
  Serial.println(url);
  
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + String(EIOT_IP_ADDRESS) + "\r\n" + 
               "Connection: close\r\n" + 
              // "Authorization: Basic " + unameenc + " \r\n" + 
               "Content-Length: 0\r\n" + 
               "\r\n");

  delay(100);
  while(client.available()){
   String line = client.readStringUntil('\r');
   Serial.print(line);
 
  }
    Serial.println();
  Serial.println("Connection closed");
}