ENV II Unit: M5Stack ATOM Matrix
atom_env_web_test
code: main.cpp
const char* ssid = "Buffalo-G-1250";
const char* password = "dvvrrefkgppvs";
WebServer server(80);
Adafruit_SHT31 sht31 = Adafruit_SHT31();
Adafruit_BMP280 bmp;
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
void handleRoot() {
// read temperature and humidity from SHT30
float temp = sht31.readTemperature();
float humi = sht31.readHumidity();
// get temperature and pressure from BMP280
sensors_event_t temp_event, pressure_event;
bmp_temp->getEvent(&temp_event);
bmp_pressure->getEvent(&pressure_event);
String html;
html = "<!DOCTYPE html>";
html += "<html>";
html += "<head>";
html += "<meta charset=\"utf-8\">";
html += "<title>Test</title>";
html += "</head>";
html += "<body>";
html += "Output from ENV.II UNIT";
html += "<p>";
html += "SHT30<br>";
html += "Temperature = ";
html += String(temp);
html += " *C<br>";
html += "Humidity = ";
html += String(temp);
html += "%";
html += "</p>";
html += "<p>";
html += "BMP280<br>";
html += "Temperature = ";
html += String(temp_event.temperature);
html += " *C<br>";
html += "Pressure = ";
html += String(pressure_event.pressure);
html += " hPa";
html += "</p>";
html += "</body>";
html += "</html>";
server.send(200, "text/html", html);
Serial.println("accessed on \"/\"");
}
void handleNotFound() {
server.send(404, "text/plain", "File Not Found\n\n");
Serial.println("File Not Found");
}
void setup() {
Serial.begin(115200);
M5.begin();
M5.dis.drawpix(0, 0x000000);
Wire.begin(26, 32);
Serial.println("SHT31 test");
if (! sht31.begin(0x44)) {
Serial.println("Couldn't find SHT31");
while (1) delay(1);
}
Serial.println("BMP280 test");
if (!bmp.begin(0x76)) {
Serial.println("Couldn'tfind BMP280");
while (1) delay(10);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
bmp_temp->printSensorDetails();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(".");
}
Serial.println("\r\nWiFi connected\r\nIP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("m5stack")) { // access to "m5stack.local"
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.onNotFound(handleNotFound);
server.begin();
}
void loop() {
server.handleClient();
}