Outils pour utilisateurs

Outils du site


esp8266:capteurspol
no way to compare when less than two revisions

Différences

Ci-dessous, les différences entre deux révisions de la page.


esp8266:capteurspol [2024/02/09 17:10] (Version actuelle) – créée - modification externe 127.0.0.1
Ligne 1: Ligne 1:
 +====== Wemos et capteurs , humidité DHT12, MQ-135, microparticule SDS011 vers OSC ======
 +<code>
 +// ESP_Wemos MQ-135 gaz detecteur vers OSC
 +// + mesure d'humidité DHT12
 +//
 +// https://github.com/CNMAT/OSC
 +// https://github.com/wemos/WEMOS_DHT12_Arduino_Library/tree/master/examples
 +// https://github.com/lewapek/sds-dust-sensors-arduino-library
 +//
 +#include <ESP8266WiFi.h>
 +#include <WiFiUdp.h>
 +#include "SdsDustSensor.h"
 +#include <OSCMessage.h> // lib OSC de la biblio standard adrianfreed 
 +#include <WEMOS_DHT12.h>
  
 +//#define DEBUG
 +const int GAZ1_A0 = A0;
 +WiFiUDP Udp;
 +///// FIXEZ CES VALEURS ///////////
 +const unsigned int outPort = 9001;    //port numbers for OSC
 +IPAddress outIP(192, 168, 0, 17);     // IP pc destination
 +const char* ssid           = "SNHACK";
 +const char* password       = "1234567890";
 +char* nomhost              = "GAZ1";  // le nom viendra de l'ip?
 +char* OSCVar               = "/GAZ1"; // nom du capteur et valeur OSC
 +int temps_milli             = 1000;   // temps milli entre 2 mesures
 +///////////////////////////////////
 +float humidite = 0;
 +float temperatre = 0;
 +float pm_25 = 0;
 +float pm_10 = 0;
 +int rxPin = D6; // D1 D2 utilisé par DHT12 i2c
 +int txPin = D7;
 +SdsDustSensor sds(rxPin, txPin);
 +DHT12 dht12;
 +
 +void setup() {
 +  pinMode(GAZ1_A0, INPUT);
 +  Serial.begin(115200);
 +  Serial.println(ESP.getChipId(), HEX);
 +  //setup ethernet part
 +  Serial.println();
 +  Serial.print("Gaz sur A0 et DHT12 shield vers OSC /GAZ1 ");
 +
 +  Serial.print("Connexion SSID ");
 +  Serial.println(ssid);
 +  WiFi.mode(WIFI_STA);
 +  //WiFi.hostname(nomhost);
 +  WiFi.begin(ssid, password);
 +  while (WiFi.status() != WL_CONNECTED) {
 +    delay(500);
 +    Serial.print(".");
 +  }
 +  Serial.println("");
 +  Serial.println(ssid);
 +  Serial.println("IP addresse: ");
 +  IPAddress IPLOCAL = WiFi.localIP();
 +  Serial.println("hostname: ");
 +  Serial.println(nomhost);
 +  WiFi.hostname(nomhost);
 +  Serial.println(WiFi.hostname());
 +  Serial.println("Starting UDP");
 +  Udp.begin(outPort);
 +  Serial.print("Local port: ");
 +  Serial.println(Udp.localPort());
 +  delay(100);
 +  sds.begin();
 +  Serial.println(sds.queryFirmwareVersion().toString()); // prints firmware version
 +  Serial.println(sds.setActiveReportingMode().toString()); // ensures sensor is in 'active' reporting mode
 +  Serial.println(sds.setCustomWorkingPeriod(1).toString()); // sensor sends data every 1 minutes
 +}
 +void loop() {
 +  Serial.println(analogRead(GAZ1_A0));
 +  if (dht12.get() == 0) {
 +    temperatre = (float)dht12.cTemp;
 +    humidite   = (float)dht12.humidity;
 +    Serial.print("Temperature       : ");
 +    
 +    Serial.println(temperatre);
 +    Serial.print("Humidite relative : ");
 +    Serial.println(humidite);
 +  }
 +  PmResult pm = sds.readPm();
 +  if (pm.isOk()) {
 +    pm_25 = (float)pm.pm25;
 +    pm_10 = (float)pm.pm10;
 +    Serial.print("PM2.5             = ");
 +    Serial.println(pm_25);
 +    Serial.print("PM10              = ");
 +    Serial.println(pm_10);
 +    //    Serial.println(pm.toString());
 +  } else {
 +    // notice that loop delay is set to 5s (sensor sends data every 3 minutes) and some reads are not available
 +    //Serial.print("Probleme de lecture SDS011: ");
 +    //Serial.println(pm.statusToString());
 +    Serial.print("PM2.5             : ");
 +    Serial.println(pm_25);
 +    Serial.print("PM10              : ");
 +    Serial.println(pm_10);
 +  }
 +  ///////////ENVOIS OSC //////////////
 +  OSCMessage msg(OSCVar); // /GAZ1 pour ce capteur
 +  //  les valeurs sont en long pour pd
 +  msg.add((float)analogRead(GAZ1_A0));
 +  msg.add((float)temperatre);
 +  msg.add((float)humidite);
 +  msg.add((float)pm_25);
 +  msg.add((float)pm_10);
 +
 +  Udp.beginPacket(outIP, outPort);
 +  msg.send(Udp);
 +  Udp.endPacket();
 +  msg.empty();
 +  delay(temps_milli);
 +}
 +</code>
esp8266/capteurspol.txt · Dernière modification : 2024/02/09 17:10 de 127.0.0.1