// Learn about the ESP32 WiFi simulation in
// https://docs.wokwi.com/guides/esp32-wifi
/*
  Эмуляция ESP8266

     1 ---------------------|-----------|\
                            |           | \
                            |           |  \
     2 ------x--------------|           |   |
             |              |           |   |
            | |  4.7k       |           |   |
            | |             |           |  /
             |              |           | /
     3 ------x--------------|-----------|/

  1 - Gnd
  2 - DPIO5
  3 - Vcc

*/

#include <WiFi.h>
#include "time.h"

#include <OneWire.h>
#include <DallasTemperature.h>

// #include <WiFi.h>
#include <Wire.h>


int ledPin = 25;                // Пин для Диода
boolean pOut = false;


// GPIO where the DS18B20 is connected to
const int oneWireBus = 12;     // GPIO5 (D1)

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);

// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

#define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  5        /* Time ESP32 will go to sleep (in seconds) */


#define NTP_SERVER     "pool.ntp.org"
#define UTC_OFFSET     3 * 3600
#define UTC_OFFSET_DST 0

String sTm = "000000000000";
float temperatureC = -1.0;


//String IP[] = {"122.154.139.137", "122.154.139.137"};
//String servers[] = {"www.edoc.ksu.ac.th", "www.ktm.ksu.ac.th"};
//String IP[] = {"195.34.224.1", "192.168.224.11"};
//String servers[] = {"rbc.ru", "zzzrbc1.ru"};
//String responseTime[5];
//String responseText, statusText;

const char* remote_host = "rbc.ru";


void setup() {

  pinMode(ledPin, OUTPUT);      // объявите светодиод в качестве выходного сигнала

  Serial.begin(115200);

  delay(100);

  Serial.println(" \n\n=======================================================\n");
  Serial.println(__FILE__);
  Serial.println("Compiled: " + String(__DATE__) + " " + String(__TIME__));

  Serial.println("Connecting to WiFi ");

  WiFi.begin("Wokwi-GUEST", "", 6);
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.print(WiFi.localIP());
  Serial.println("  Online");

  //Serial.println("Updating time...");

  configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);

  digitalWrite(ledPin, HIGH);  // включаем светодиод


}


int cnt = 0;


void tm_Get()
{

  char buffer[25]; // large enough for any DateTime, including invalid ones
  struct tm timeinfo;

  if (!getLocalTime(&timeinfo)) {
    sTm = "Time Err";
    return;
  }

  sprintf(buffer, "%04d%02d%02d%02d%02d%02d",
          (timeinfo.tm_year + 1970),
          timeinfo.tm_mon,
          timeinfo.tm_mday,
          timeinfo.tm_hour,
          timeinfo.tm_min,
          timeinfo.tm_sec
         );

  sTm = String(buffer);

}





void loop() {

  // put your main code here, to run repeatedly:

  int val = digitalRead(ledPin);  // считывание входного значения светодиод

  if (val != HIGH) {            // проверьте, является ли входной сигнал HIGH
    digitalWrite(ledPin, HIGH);  // Если да то включаем светодиод
  }
  else {
    digitalWrite(ledPin, LOW); // turn LED OFF
   }
  delay(1000); // TODO: Build something amazing!


  if (cnt++ > 5)
  {

    tm_Get();

    sensors.requestTemperatures();
    temperatureC = sensors.getTempCByIndex(0);

    Serial.printf("%s  Temperature=%s ºC\n", sTm.c_str(), String(temperatureC, 1));

    cnt = 0;
  }


}
Loading
ds18b20