Add sensors programmes and schemas
This commit is contained in:
parent
b8f1add31f
commit
fb6be459c2
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
|
|
@ -0,0 +1,14 @@
|
|||
ESP 8266
|
||||
=========
|
||||
|
||||
Ici ce trouve le schéma électrique et quelques explication sur comment programmer un ESP 8266.
|
||||
|
||||
L'ESP 8266 est un module WiFi qui comporte un petit micro-controleur qui peux être programmé de la même manière qu'un Arduino.
|
||||
Pour cela, il faut installer un plugin à l'IDE Arduino, en suivant les indcations sur [le github][1].
|
||||
|
||||
* Le bouton Reset sert à effacer le programme contenue dans le micro-controleur.
|
||||
* Le bouton de programmation doit être enfoncé (et mettre le GPIO_0 à la masse) pour effectuer le transfert du programme sur le micro-controleur.
|
||||
* Il faut relacher le bouton de programmation lorsque que l'on débranche l'ESP 8266. Sinon l'effet sera le même qu'un appuye sur le bouton Reset.
|
||||
|
||||
|
||||
[1]: https://github.com/esp8266/Arduino
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Temperature sensor
|
||||
=========
|
||||
|
||||
Ici ce trouve le schéma électrique et le code nécessaire à la réalisation du capteur de température.
|
||||
|
||||
|
||||
Materiels
|
||||
========
|
||||
* Programmeur USB (PL2303HXD USB-TTL)
|
||||
* Sonde de temperature (DS18B20)
|
||||
* Module WiFi (ESP8266)
|
||||
* 2 résistances de 2.2 kΩ
|
||||
* 1 résistance de 470 Ω
|
||||
* Chargeur de téléphone qui doit fournir au moins 1A
|
||||
|
||||
Le module WiFi est doté d'un micro controleur qui peux être programmé à la manière d'un Arduino (cf le schéma électrique pour programmer le module ESP 8266).
|
||||
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Send temperature via HTTP GET requests to $host service.
|
||||
* Measure temperature with interval given bye the server.
|
||||
* Version 1.1.0
|
||||
*/
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
const char* ssid = "TNCAP3F2E03";
|
||||
const char* password = "73ABCCAA87";
|
||||
|
||||
const char* host = "datahouse.kingpenguin.tk";
|
||||
const int httpPort = 80;
|
||||
const int DEFAULT_INTERVAL = 3600;
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
String MAC = "";
|
||||
|
||||
// broche data du DS18B20
|
||||
#define ONE_WIRE_BUS 2
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
DallasTemperature DS18B20(&oneWire);
|
||||
|
||||
// Wait for x second.
|
||||
void sleepSec(int sec) {
|
||||
for (int i=0; i<1000; i++) {
|
||||
delay(sec);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the MAC address of the device.
|
||||
String getMacAddress() {
|
||||
String macReturn = "";
|
||||
unsigned char mac[6];
|
||||
if(WiFi.macAddress(mac) != 0) {
|
||||
for(int i=0; i<6; i++) {
|
||||
if(mac[i]<16) {
|
||||
macReturn = "0";
|
||||
}
|
||||
macReturn += String(mac[i], HEX);
|
||||
macReturn += (i < 5) ? ":" : "";
|
||||
}
|
||||
}
|
||||
return macReturn;
|
||||
}
|
||||
|
||||
// Get the temperature.
|
||||
float getTemp() {
|
||||
float t;
|
||||
do {
|
||||
DS18B20.requestTemperatures();
|
||||
t = DS18B20.getTempCByIndex(0);
|
||||
} while (t == 85.0 || t == (-127.0));
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// WiFi.macAddress(mac);
|
||||
MAC = getMacAddress();
|
||||
Serial.print("MAC address: ");
|
||||
Serial.println(MAC);
|
||||
|
||||
// We start by connecting to a WiFi network
|
||||
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
float temp;
|
||||
int nextInterval;
|
||||
|
||||
void loop() {
|
||||
// On mesure la température
|
||||
temp = getTemp();
|
||||
temp += 0.5;
|
||||
int temperature = (int) temp;
|
||||
|
||||
// Use WiFiClient class to create TCP connections
|
||||
WiFiClient client;
|
||||
if (!client.connect(host, httpPort)) {
|
||||
Serial.print("connection failed on host ");
|
||||
Serial.print(host);
|
||||
Serial.print(":");
|
||||
Serial.println(host);
|
||||
return;
|
||||
}
|
||||
|
||||
// We now create a URI for the request
|
||||
String url = "/add/temp/"+MAC+"/"+temperature;
|
||||
|
||||
Serial.print("Requesting URL: ");
|
||||
Serial.println(url);
|
||||
|
||||
// This will send the request to the server
|
||||
client.println("GET "+url+" HTTP/1.1");
|
||||
client.println("Host: "+String(host));
|
||||
client.println("Connection: keep-alive");
|
||||
// client.println("Connection: close");
|
||||
client.println();
|
||||
delay(10);
|
||||
|
||||
Serial.println();
|
||||
String line = "";
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
line += c;
|
||||
}
|
||||
Serial.println(line);
|
||||
|
||||
nextInterval = line.toInt();
|
||||
if (nextInterval == 0) {
|
||||
nextInterval = DEFAULT_INTERVAL;
|
||||
}
|
||||
|
||||
Serial.print("Temperature sent: ");
|
||||
Serial.print(temperature);
|
||||
Serial.println("°C");
|
||||
|
||||
|
||||
sleepSec(nextInterval);
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
Loading…
Reference in New Issue