Created
January 1, 2021 01:09
-
-
Save ebith/92a684b632361d3cf58021affaae4f20 to your computer and use it in GitHub Desktop.
M5 ATOM(ESP32)で温度・湿度・気圧(BME280)をInfluxDBに投げるやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FASTLED_INTERNAL | |
#include <Arduino.h> | |
#include <WiFi.h> | |
#include <FastLED.h> | |
#include <Adafruit_BME280.h> | |
#include <InfluxDbClient.h> | |
const int NUM_LEDS = 1; | |
const int LED_PIN = 27; | |
static CRGB leds[NUM_LEDS]; | |
Adafruit_BME280 bme; | |
Adafruit_Sensor *bme_temp = bme.getTemperatureSensor(); | |
Adafruit_Sensor *bme_pressure = bme.getPressureSensor(); | |
Adafruit_Sensor *bme_humidity = bme.getHumiditySensor(); | |
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_DB_NAME); | |
Point sensor("sensor"); | |
void setup() { | |
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); | |
FastLED.setBrightness(1); | |
leds[0] = CRGB::Black; | |
FastLED.show(); | |
Wire.begin(21, 22); | |
bme.begin(0x76, &Wire); | |
bme_temp->printSensorDetails(); | |
bme_pressure->printSensorDetails(); | |
bme_humidity->printSensorDetails(); | |
sensor.addTag("location", "hallway"); | |
} | |
void loop() { | |
if (WiFi.status() == WL_CONNECTED) { | |
sensors_event_t temp_event, pressure_event, humidity_event; | |
bme_temp->getEvent(&temp_event); | |
bme_pressure->getEvent(&pressure_event); | |
bme_humidity->getEvent(&humidity_event); | |
sensor.clearFields(); | |
sensor.addField("temperature", temp_event.temperature); | |
sensor.addField("pressure", pressure_event.pressure); | |
sensor.addField("humidity", humidity_event.relative_humidity); | |
client.writePoint(sensor); | |
delay(20 * 1000); | |
} else { | |
leds[0] = CRGB::Red; | |
FastLED.show(); | |
WiFi.begin(WIFI_SSID, WIFI_PASS); | |
int wifiReconnectCount = 0; | |
while (WiFi.status() != WL_CONNECTED) { | |
if (wifiReconnectCount >= 200) { ESP.restart(); } | |
wifiReconnectCount++; | |
delay(100); | |
} | |
leds[0] = CRGB::Green; | |
FastLED.show(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; PlatformIO Project Configuration File | |
; | |
; Build options: build flags, source filter | |
; Upload options: custom upload port, speed and extra flags | |
; Library options: dependencies, extra library storages | |
; Advanced options: extra scripting | |
; | |
; Please visit documentation for the other options and examples | |
; https://docs.platformio.org/page/projectconf.html | |
[env:m5stick-c] | |
platform = espressif32 | |
board = m5stick-c | |
framework = arduino | |
monitor_speed = 115200 | |
board_build.f_cpu = 80000000L | |
lib_deps = | |
adafruit/Adafruit BME280 Library@^2.1.2 | |
tobiasschuerg/ESP8266 Influxdb@^3.7.0 | |
fastled/FastLED@^3.4.0 | |
build_flags = | |
-D WIFI_SSID='"${sysenv.WIFI_SSID}"' | |
-D WIFI_PASS='"${sysenv.WIFI_PASS}"' | |
-D INFLUXDB_URL='"${sysenv.INFLUXDB_URL}"' | |
-D INFLUXDB_DB_NAME='"${sysenv.INFLUXDB_DB_NAME}"' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$env:WIFI_SSID = "**********" | |
$env:WIFI_PASS = "**********" | |
$env:INFLUXDB_URL = "http://192.168.0.81:8086" | |
$env:INFLUXDB_DB_NAME = "homestats" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment