ESP8266 DS18b20 Senzor temperatura

de George Sand


Adaugat in 2017-07-11 02:50:08



Termometru digital

folosind WeMos D1 Mini ESP8266 si senzor temperatura DS18b20

Librarii de care avem nevoie:
esp8266 https://github.com/esp8266/Arduino
OneWire https://github.com/PaulStoffregen/OneWire
Dallas Temeperature https://github.com/milesburton/Arduino-Temperature-Control-Library

Pentru a putea folosi ide-ul Arduino sa programam WeMos D1 Mini ESP8266, trebuie instalat board-ul aferent adaugam link-ul http://arduino.esp8266.com/stable/package_esp8266com_index.json in Arduino IDE File -> Preferences -> additional boards manager URLs.
Dupa introducere incarcam board-ul din meniul Sketch -> Manage Libraries si cautam dupa denumirea ESP8266, dupa cautare instalam ESP8266 Microgear.
Dupa instalare vom selecta placa Tools -> Board: -> WeMos D1 R2 mini si updatati parametrul upload speed la 115200.

Cod sursa .ino :

#include <ESP8266WiFi.h>
#include <Base64.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "ESP8266HTTPClient.h"


//AP definitions
#define AP_SSID "radcom"
#define AP_PASSWORD "ocolivie"

#define ONE_WIRE_BUS 2  // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

void setup() {
  // Serial.begin(115200);
  // pinMode(LED_BUILTIN, OUTPUT);

}

void loop() {

  wifiConnect();
  //ledblink();
  DS18B20.requestTemperatures();
  int temp = DS18B20.getTempCByIndex(0);
  sendTeperature(temp);
  delay(1800000);
  //delay(5000);
}
void ledblink() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
  // but actually the LED is on; this is because
  // it is acive low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);
 }

void wifiConnect()
{
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(500);
  WiFi.begin(AP_SSID, AP_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    // Serial.print(".");
  }
  // Serial.println("WiFi connected");
}

void sendTeperature(int temp)
{

  HTTPClient http;
  http.begin("http://iot.micronikgrupm.ro/xxxx");
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  String strTemp = String(temp);
  String concTemp = String("idzona=YYYYY&temp=" + strTemp);
  http.POST(concTemp);
  http.writeToStream(&Serial);
  http.end();
  delay(500);

}

link proiect terminat http://iot.genportal.ro/


Tag-uri cautare WeMos D1 R2 mini OneWire IoT ESP8266 DS18b20 Dallas Temeperature
Trimite unui prieten aceasta postare
sau distribuie postarea la tine pe perete
Inapoi

Lasa un comentariu