Luis Rodil-Fernandez
3 years ago
commit
aa8810d83a
5 changed files with 6140 additions and 0 deletions
-
277ENCSYS-FEDE-OSC-HUM-DEBUG.ino
-
101OSC.h
-
87OTA.h
-
20config.h
-
5655fontdef.h
@ -0,0 +1,277 @@ |
|||||
|
// ----- TeZ ---- DHT Display on OLED screen -----
|
||||
|
//* OLED DISPLAY 3.3V(VCC), GND, SCL (21), SDA (22) [ESP32]
|
||||
|
//* model: SSD1306 Resolution: 128 x 64 (small = 128 x 32)
|
||||
|
// FONTS >> in file OLEDdisplayFonts.h
|
||||
|
// ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24
|
||||
|
// SansSerif_plain_10, SansSerif_plain_12
|
||||
|
// Dingbats__12
|
||||
|
// Monospaced_plain_8, Monospaced_plain_10, Monospaced_plain_12, Monospaced_bold_10, Monospaced_bold_16, Monospaced_bold_24 //
|
||||
|
// ceated with http://oleddisplay.squix.ch/
|
||||
|
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
|
||||
|
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
|
||||
|
// https://learn.adafruit.com/dht/overview
|
||||
|
|
||||
|
//F.M. ENCSYS edit 1
|
||||
|
|
||||
|
#include "OTA.h"
|
||||
|
#include "OSC.h"
|
||||
|
|
||||
|
#include <Adafruit_Sensor.h>
|
||||
|
#include <DHT.h>
|
||||
|
#include <DHT_U.h>
|
||||
|
#include <Wire.h>
|
||||
|
#include <Adafruit_GFX.h>
|
||||
|
#include "fontdef.h"
|
||||
|
//#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
|
||||
|
#include "SSD1306Wire.h"
|
||||
|
#include "OLEDDisplayUi.h"
|
||||
|
#include <driver/adc.h>
|
||||
|
|
||||
|
// Initialize the OLED display using Wire library
|
||||
|
SSD1306Wire display(0x3c, 21, 22); |
||||
|
|
||||
|
#define DHTPIN 25 // Digital pin connected to the DHT sensor
|
||||
|
|
||||
|
// Uncomment the type of sensor in use:
|
||||
|
#define DHTTYPE DHT11 // DHT 11
|
||||
|
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
|
||||
|
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
|
||||
|
DHT_Unified dht(DHTPIN, DHTTYPE); |
||||
|
|
||||
|
uint32_t delayMS; |
||||
|
|
||||
|
//bool light = false;
|
||||
|
|
||||
|
int LEDpin = 16; |
||||
|
//int SMOKETIME = 5000;
|
||||
|
//bool SMOKEFLAG = true;
|
||||
|
|
||||
|
|
||||
|
///////////////////////////////////////////////////////
|
||||
|
void setup() { |
||||
|
|
||||
|
APConnect(); |
||||
|
setupOTA(); |
||||
|
Udp.begin(rxport); |
||||
|
|
||||
|
//Serial.begin(115200);
|
||||
|
|
||||
|
pinMode(LEDpin, OUTPUT); |
||||
|
pinMode(4, OUTPUT); |
||||
|
|
||||
|
digitalWrite(4, false); |
||||
|
fog = false; |
||||
|
|
||||
|
|
||||
|
|
||||
|
// Initialising the OLED display
|
||||
|
display.init(); |
||||
|
display.flipScreenVertically(); |
||||
|
display.setTextAlignment(TEXT_ALIGN_LEFT); |
||||
|
display.clear(); |
||||
|
|
||||
|
display.setFont(Monospaced_bold_16); |
||||
|
display.drawString(0, 0, "Hello Human!"); |
||||
|
display.setFont(Monospaced_plain_12); |
||||
|
display.drawString(20, 30, "How are you"); |
||||
|
display.drawString(40, 50, "today?"); |
||||
|
|
||||
|
display.display(); |
||||
|
|
||||
|
delay(3000); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
// Initialize DHT device.
|
||||
|
dht.begin(); |
||||
|
Serial.println(F("DHTxx Unified Sensor Example")); |
||||
|
// Print temperature sensor details.
|
||||
|
sensor_t sensor; |
||||
|
dht.temperature().getSensor(&sensor); |
||||
|
Serial.println(F("------------------------------------")); |
||||
|
Serial.println(F("Temperature Sensor")); |
||||
|
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name); |
||||
|
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); |
||||
|
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); |
||||
|
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C")); |
||||
|
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C")); |
||||
|
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C")); |
||||
|
Serial.println(F("------------------------------------")); |
||||
|
// Print humidity sensor details.
|
||||
|
dht.humidity().getSensor(&sensor); |
||||
|
Serial.println(F("Humidity Sensor")); |
||||
|
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name); |
||||
|
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); |
||||
|
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); |
||||
|
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%")); |
||||
|
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%")); |
||||
|
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%")); |
||||
|
Serial.println(F("------------------------------------")); |
||||
|
// Set delay between sensor readings based on sensor details.
|
||||
|
delayMS = sensor.min_delay / 1000; |
||||
|
} |
||||
|
|
||||
|
void humiditycontrol() |
||||
|
{ |
||||
|
delay(delayMS); |
||||
|
// Get humidity event and compare it to the wanted value
|
||||
|
sensors_event_t event; |
||||
|
dht.humidity().getEvent(&event); |
||||
|
|
||||
|
if ((int(event.relative_humidity)) > (int(humidityctrl))){ |
||||
|
fogstate = false; |
||||
|
} |
||||
|
else { |
||||
|
//delay(100);
|
||||
|
// delay(delayMS);
|
||||
|
fogstate = true; |
||||
|
//if (prevfogstate != fogstate){
|
||||
|
//delay(100);
|
||||
|
//}
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void fogcontrol() |
||||
|
{ |
||||
|
if (fogstate == 1){ |
||||
|
digitalWrite(4, true); |
||||
|
delay (100); |
||||
|
prevfogstate = bool(fogstate); |
||||
|
digitalWrite(4, false); |
||||
|
delay (5000); |
||||
|
//prevfogstate = int(fogstate);
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
else if (fogstate == 0){ |
||||
|
|
||||
|
if (prevfogstate != fogstate){ |
||||
|
//delay (100);
|
||||
|
//digitalWrite(4, true);
|
||||
|
delay (100); |
||||
|
digitalWrite(4, false); |
||||
|
|
||||
|
prevfogstate = bool(fogstate); |
||||
|
} |
||||
|
else{ |
||||
|
digitalWrite(4, false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
///////////////////////////////////////////////////////
|
||||
|
void loop() { |
||||
|
|
||||
|
osc_message_pump(); |
||||
|
ArduinoOTA.handle(); |
||||
|
|
||||
|
|
||||
|
// FOG SWITCH
|
||||
|
//delay(SMOKETIME);
|
||||
|
//SMOKEFLAG = !(SMOKEFLAG);
|
||||
|
//digitalWrite(4, fog);
|
||||
|
digitalWrite(LEDpin, light); |
||||
|
|
||||
|
|
||||
|
humiditycontrol(); |
||||
|
fogcontrol(); |
||||
|
/////////////////////// atomizer toggle
|
||||
|
|
||||
|
|
||||
|
|
||||
|
Serial.println(int(humidityctrl)); |
||||
|
Serial.print(F("fog state: ")); |
||||
|
if (fogstate == 1){ |
||||
|
Serial.println (F("active")); |
||||
|
} |
||||
|
else{ |
||||
|
Serial.println (F("off")); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
//////////////////
|
||||
|
|
||||
|
// SENSOR AND DISPLAY
|
||||
|
display.clear(); |
||||
|
|
||||
|
// Delay between measurements.
|
||||
|
delay(delayMS); |
||||
|
// Get temperature event and print its value.
|
||||
|
sensors_event_t event; |
||||
|
dht.temperature().getEvent(&event); |
||||
|
if (isnan(event.temperature)) { |
||||
|
Serial.println(F("Error reading temperature!")); |
||||
|
} |
||||
|
else { |
||||
|
display.setFont(Monospaced_bold_16); |
||||
|
display.drawString(0, 10, "Temp:"); |
||||
|
display.drawString(50, 10, String(int(event.temperature)) + " c" ); |
||||
|
|
||||
|
Serial.print(F("Temperature: ")); |
||||
|
Serial.print(event.temperature); |
||||
|
Serial.println(F("°C")); |
||||
|
} |
||||
|
// Get humidity event and print its value.
|
||||
|
dht.humidity().getEvent(&event); |
||||
|
if (isnan(event.relative_humidity)) { |
||||
|
Serial.println(F("Error reading humidity!")); |
||||
|
} |
||||
|
else { |
||||
|
display.setFont(Monospaced_bold_16); |
||||
|
display.drawString(0, 50, "Hum:"); |
||||
|
display.drawString(50, 50, String(int(event.relative_humidity)) + " %"); |
||||
|
|
||||
|
Serial.print(F("Humidity: ")); |
||||
|
Serial.print(event.relative_humidity); |
||||
|
Serial.println(F("%")); |
||||
|
Serial.println (int(event.relative_humidity)); |
||||
|
Serial.println(fog); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
display.display(); |
||||
|
|
||||
|
|
||||
|
// printBuffer();
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
////////////////////////////////////////////
|
||||
|
void printBuffer(void) { |
||||
|
// Initialize the log buffer
|
||||
|
// allocate memory to store 8 lines of text and 30 chars per line.
|
||||
|
display.setLogBuffer(5, 30); |
||||
|
|
||||
|
// Some test data
|
||||
|
const char* test[] = { |
||||
|
"Hello", |
||||
|
"World" , |
||||
|
"----", |
||||
|
"Show off", |
||||
|
"how", |
||||
|
"the log buffer", |
||||
|
"is", |
||||
|
"working.", |
||||
|
"Even", |
||||
|
"scrolling is", |
||||
|
"working" |
||||
|
}; |
||||
|
|
||||
|
for (uint8_t i = 0; i < 11; i++) { |
||||
|
display.clear(); |
||||
|
// Print to the screen
|
||||
|
display.println(test[i]); |
||||
|
// Draw it to the internal screen buffer
|
||||
|
display.drawLogBuffer(0, 0); |
||||
|
// Display it on the screen
|
||||
|
display.display(); |
||||
|
delay(500); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,101 @@ |
|||||
|
/// READ OSC MESSAGES /// |
||||
|
|
||||
|
#include <WiFiUdp.h> |
||||
|
#include <OSCMessage.h> |
||||
|
|
||||
|
bool light = false; |
||||
|
bool fog = false; |
||||
|
int humidityctrl = 80; |
||||
|
bool fogstate = false; |
||||
|
bool prevfogstate = false; |
||||
|
|
||||
|
WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP |
||||
|
// const IPAddress dest(192, 168, 8, 255); |
||||
|
const unsigned int rxport = 54321; // remote port to receive OSC |
||||
|
const unsigned int txport = 12345; // local port to listen for OSC packets (actually not used for sending) |
||||
|
|
||||
|
|
||||
|
|
||||
|
void on_light(OSCMessage &msg, int addrOffset) { |
||||
|
|
||||
|
|
||||
|
int lighton; |
||||
|
|
||||
|
if(msg.isFloat(0)){ |
||||
|
lighton = msg.getFloat(0); |
||||
|
} |
||||
|
|
||||
|
if (lighton){ |
||||
|
light = true ; |
||||
|
|
||||
|
}else{ |
||||
|
light = false; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
//////////////////////////////// |
||||
|
/////////////////////////////// |
||||
|
void on_fog(OSCMessage &msg, int addrOffset) { |
||||
|
|
||||
|
int fogon; |
||||
|
|
||||
|
if(msg.isFloat(0)){ |
||||
|
fogon = msg.getFloat(0); |
||||
|
} |
||||
|
|
||||
|
if (fogon){ |
||||
|
fog = true ; |
||||
|
|
||||
|
}else{ |
||||
|
fog = false ; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void on_humidity(OSCMessage &msg, int addrOffset) { |
||||
|
|
||||
|
int humidityon; |
||||
|
|
||||
|
if(msg.isFloat(0)){ |
||||
|
humidityon = msg.getFloat(0); |
||||
|
} |
||||
|
|
||||
|
humidityctrl = int(humidityon); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
//////////////////////////////// |
||||
|
/////////////////////////////// |
||||
|
|
||||
|
|
||||
|
void osc_message_pump() { |
||||
|
OSCMessage in; |
||||
|
int size; |
||||
|
|
||||
|
if( (size = Udp.parsePacket()) > 0) |
||||
|
{ |
||||
|
Serial.println("processing OSC package"); |
||||
|
// parse incoming OSC message |
||||
|
while(size--) { |
||||
|
in.fill( Udp.read() ); |
||||
|
} |
||||
|
|
||||
|
if(!in.hasError()) { |
||||
|
in.route("/light", on_light); |
||||
|
in.route("/fog", on_fog); |
||||
|
in.route("/humidity", on_humidity); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
Serial.println("OSC MESSAGE RECEIVED"); |
||||
|
// Serial.println (light); |
||||
|
// Serial.println (fog); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
/////////////////////////////// |
||||
|
|
||||
|
|
@ -0,0 +1,87 @@ |
|||||
|
#include <WiFi.h> |
||||
|
#include <ESPmDNS.h> |
||||
|
#include <WiFiUdp.h> |
||||
|
#include <ArduinoOTA.h> |
||||
|
#include "config.h" |
||||
|
|
||||
|
void APConnect(){ |
||||
|
|
||||
|
Serial.println("Configuring access point..."); |
||||
|
|
||||
|
//WiFi.mode(WIFI_AP); |
||||
|
WiFi.softAP(ssid, pass); |
||||
|
Serial.println("Wait 100 ms for AP_START..."); |
||||
|
delay(100); |
||||
|
|
||||
|
Serial.println("Set softAPConfig"); |
||||
|
IPAddress Ip(192, 168, 10, 23); |
||||
|
IPAddress NMask(255, 255, 255, 0); |
||||
|
WiFi.softAPConfig(Ip, Ip, NMask); |
||||
|
|
||||
|
IPAddress myIP = WiFi.softAPIP(); |
||||
|
Serial.print("AP IP address: "); |
||||
|
Serial.println(myIP); |
||||
|
} |
||||
|
|
||||
|
void WiFiConnect(){ |
||||
|
|
||||
|
Serial.println("Booting"); |
||||
|
WiFi.mode(WIFI_STA); |
||||
|
WiFi.begin(ssidW, passwordW); |
||||
|
while (WiFi.waitForConnectResult() != WL_CONNECTED) { |
||||
|
Serial.println("Connection Failed! Rebooting..."); |
||||
|
delay(5000); |
||||
|
ESP.restart(); |
||||
|
} |
||||
|
} |
||||
|
void setupOTA() |
||||
|
{ |
||||
|
Serial.begin(115200); |
||||
|
// Port defaults to 3232 |
||||
|
ArduinoOTA.setPort(3232); |
||||
|
|
||||
|
// Hostname defaults to esp3232-[MAC] |
||||
|
ArduinoOTA.setHostname("ENCSYS"); |
||||
|
|
||||
|
// No authentication by default |
||||
|
// ArduinoOTA.setPassword("admin"); |
||||
|
|
||||
|
// Password can be set with it's md5 value as well |
||||
|
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3 |
||||
|
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3"); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
ArduinoOTA |
||||
|
.onStart([]() { |
||||
|
String type; |
||||
|
if (ArduinoOTA.getCommand() == U_FLASH) |
||||
|
type = "sketch"; |
||||
|
else // U_SPIFFS |
||||
|
type = "filesystem"; |
||||
|
|
||||
|
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() |
||||
|
Serial.println("Start updating " + type); |
||||
|
}) |
||||
|
.onEnd([]() { |
||||
|
Serial.println("\nEnd"); |
||||
|
}) |
||||
|
.onProgress([](unsigned int progress, unsigned int total) { |
||||
|
Serial.printf("Progress: %u%%\r", (progress / (total / 100))); |
||||
|
}) |
||||
|
.onError([](ota_error_t error) { |
||||
|
Serial.printf("Error[%u]: ", error); |
||||
|
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); |
||||
|
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); |
||||
|
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); |
||||
|
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); |
||||
|
else if (error == OTA_END_ERROR) Serial.println("End Failed"); |
||||
|
}); |
||||
|
|
||||
|
ArduinoOTA.begin(); |
||||
|
|
||||
|
Serial.println("Ready"); |
||||
|
Serial.print("IP address: "); |
||||
|
Serial.println(WiFi.localIP()); |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
//Wifi name and pass |
||||
|
const char* ssidW = "ANTIMATERIA"; |
||||
|
const char* passwordW = "ExoPlanet.2323.opto-bl00dy-ne7"; |
||||
|
//Acess Point name and pass |
||||
|
const char* ssid = "ENCSYS"; |
||||
|
const char* pass = "ENCSYS232323"; |
||||
|
WiFiServer server(80); |
||||
|
|
||||
|
// it wil set the static IP address to 192, 168, 10, 23 |
||||
|
IPAddress local_IP(192, 168, 10, 23); |
||||
|
//it wil set the gateway static IP address to 192, 168, 10,1 |
||||
|
IPAddress gateway(192, 168, 10, 1); |
||||
|
|
||||
|
// Following three settings are optional |
||||
|
IPAddress subnet(255, 255, 0, 0); |
||||
|
IPAddress primaryDNS(8, 8, 8, 8); |
||||
|
IPAddress secondaryDNS(8, 8, 4, 4); |
||||
|
|
||||
|
|
||||
|
int WID = 1; // ID# OF THIS BOARD |
5655
fontdef.h
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue