Merged from master
This commit is contained in:
		| @@ -13,6 +13,6 @@ | |||||||
| #define HOMIE_SETTINGS | #define HOMIE_SETTINGS | ||||||
|  |  | ||||||
| #define HOMIE_FIRMWARE_NAME     "RoomSensor" | #define HOMIE_FIRMWARE_NAME     "RoomSensor" | ||||||
| #define HOMIE_FIRMWARE_VERSION  "2.0.0" | #define HOMIE_FIRMWARE_VERSION  "2.1.0" | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ | |||||||
| platform = espressif8266 | platform = espressif8266 | ||||||
| board = d1_mini | board = d1_mini | ||||||
| framework = arduino | framework = arduino | ||||||
| build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -D BME680 | build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -D BMP280 | ||||||
| ; build_flag needs define the Bosch sensor... | ; build_flag needs define the Bosch sensor... | ||||||
| ; -D BMP280 | ; -D BMP280 | ||||||
| ;or | ;or | ||||||
| @@ -25,4 +25,4 @@ lib_deps = https://github.com/homieiot/homie-esp8266.git#develop | |||||||
|             adafruit/Adafruit BMP280 Library @ ^2.4.2 |             adafruit/Adafruit BMP280 Library @ ^2.4.2 | ||||||
|             adafruit/Adafruit BME680 Library @ ^2.0.1 |             adafruit/Adafruit BME680 Library @ ^2.0.1 | ||||||
|  |  | ||||||
| upload_port = /dev/ttyUSB1 | upload_port = /dev/ttyUSB0 | ||||||
							
								
								
									
										52
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								src/main.cpp
									
									
									
									
									
								
							| @@ -50,6 +50,10 @@ | |||||||
|  |  | ||||||
| #define SEALEVELPRESSURE_HPA (1013.25) | #define SEALEVELPRESSURE_HPA (1013.25) | ||||||
|  |  | ||||||
|  | #define BUTTON_MAX_CYCLE        10000U  /**< Action: Reset configuration */ | ||||||
|  | #define BUTTON_MIN_ACTION_CYCLE 55U     /**< Minimum cycle to react on the button (e.g. 5 second) */ | ||||||
|  | #define BUTTON_CHECK_INTERVALL  100U     /**< Check every 100 ms the button state */ | ||||||
|  |  | ||||||
| #define LOG_TOPIC "log\0" | #define LOG_TOPIC "log\0" | ||||||
| #define MQTT_LEVEL_ERROR    1 | #define MQTT_LEVEL_ERROR    1 | ||||||
| #define MQTT_LEVEL_WARNING  10 | #define MQTT_LEVEL_WARNING  10 | ||||||
| @@ -80,6 +84,7 @@ | |||||||
| #define NODE_AMBIENT                    "ambient" | #define NODE_AMBIENT                    "ambient" | ||||||
|  |  | ||||||
| #define MQTT_DUMMYHOST                  "localhost" | #define MQTT_DUMMYHOST                  "localhost" | ||||||
|  | #define NODE_BUTTON                     "button" | ||||||
| /****************************************************************************** | /****************************************************************************** | ||||||
|  *                                     TYPE DEFS |  *                                     TYPE DEFS | ||||||
|  ******************************************************************************/ |  ******************************************************************************/ | ||||||
| @@ -98,6 +103,7 @@ bool mConfigured = false; | |||||||
| bool mConnected = false; | bool mConnected = false; | ||||||
| bool mFailedI2Cinitialization = false; | bool mFailedI2Cinitialization = false; | ||||||
| AsyncWebServer* mHttp = NULL; | AsyncWebServer* mHttp = NULL; | ||||||
|  | long mLastButtonAction = 0; | ||||||
|  |  | ||||||
| /******************************* Sensor data **************************/ | /******************************* Sensor data **************************/ | ||||||
| HomieNode particle(NODE_PARTICLE, "particle", "number"); /**< Measuret in micro gram per quibik meter air volume */ | HomieNode particle(NODE_PARTICLE, "particle", "number"); /**< Measuret in micro gram per quibik meter air volume */ | ||||||
| @@ -108,6 +114,7 @@ HomieNode altitudeNode(NODE_ALTITUDE, "Altitude", "number"); | |||||||
| HomieNode gasNode(NODE_GAS, "Gas", "number"); | HomieNode gasNode(NODE_GAS, "Gas", "number"); | ||||||
| HomieNode humidityNode(NODE_HUMIDITY, "Humidity", "number"); | HomieNode humidityNode(NODE_HUMIDITY, "Humidity", "number"); | ||||||
| #endif | #endif | ||||||
|  | HomieNode buttonNode(NODE_BUTTON, "Button", "number"); | ||||||
|  |  | ||||||
| /****************************** Output control ***********************/ | /****************************** Output control ***********************/ | ||||||
| HomieNode ledStripNode /* to rule them all */("led", "RGB led", "color"); | HomieNode ledStripNode /* to rule them all */("led", "RGB led", "color"); | ||||||
| @@ -252,7 +259,9 @@ void updateLEDs() { | |||||||
|       } |       } | ||||||
|       strip.show(); |       strip.show(); | ||||||
|   } else { |   } else { | ||||||
|  | #ifdef BME680 | ||||||
|     bmx.performReading(); |     bmx.performReading(); | ||||||
|  | #endif | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -287,15 +296,15 @@ String sensorAsJSON(void) { | |||||||
|   String buffer; |   String buffer; | ||||||
|   StaticJsonDocument<500> doc; |   StaticJsonDocument<500> doc; | ||||||
|  |  | ||||||
|   doc["temp"] = String(bmx.temperature); |   doc["temp"] = String(bmx.readTemperature()); | ||||||
| #ifdef BME680 | #ifdef BME680 | ||||||
|    doc["gas"] = String((bmx.gas_resistance / 1000.0)); |    doc["gas"] = String((bmx.gas_resistance / 1000.0)); | ||||||
|   doc["humidity"] = String(bmx.humidity); |   doc["humidity"] = String(bmx.humidity); | ||||||
| #endif | #endif | ||||||
|   float atmospheric = bmx.pressure / 100.0F; |   float atmospheric = bmx.readPressure() / 100.0F; | ||||||
|   float altitude = 44330.0 * (1.0 - pow(atmospheric / SEALEVELPRESSURE_HPA, 0.1903)); |   float altitude = 44330.0 * (1.0 - pow(atmospheric / SEALEVELPRESSURE_HPA, 0.1903)); | ||||||
|   doc["altitude"] = String(altitude); |   doc["altitude"] = String(altitude); | ||||||
|   doc["pressure"] = String(bmx.pressure / 100.0F); |   doc["pressure"] = String(atmospheric); | ||||||
|   doc["particle"] = String(mParticle_pM25); |   doc["particle"] = String(mParticle_pM25); | ||||||
|   serializeJson(doc, buffer); |   serializeJson(doc, buffer); | ||||||
|   return buffer; |   return buffer; | ||||||
| @@ -341,8 +350,18 @@ void loopHandler() | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /* Clean cycles buttons */ | ||||||
|  |     if (mButtonPressed <= BUTTON_MIN_ACTION_CYCLE) { | ||||||
|  |       buttonNode.setProperty(NODE_BUTTON).send("0"); | ||||||
|  |     } | ||||||
|     lastRead = millis(); |     lastRead = millis(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /* if the user sees something via the LEDs, inform MQTT, too */ | ||||||
|  |   if (mButtonPressed > BUTTON_MIN_ACTION_CYCLE) { | ||||||
|  |     buttonNode.setProperty(NODE_BUTTON).send(String(mButtonPressed)); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   // Feed the dog -> ESP stay alive |   // Feed the dog -> ESP stay alive | ||||||
|   ESP.wdtFeed(); |   ESP.wdtFeed(); | ||||||
| } | } | ||||||
| @@ -427,7 +446,8 @@ void setup() | |||||||
|   ledStripNode.advertise(NODE_AMBIENT).setName("All Leds") |   ledStripNode.advertise(NODE_AMBIENT).setName("All Leds") | ||||||
|                             .setDatatype("color").setFormat("rgb") |                             .setDatatype("color").setFormat("rgb") | ||||||
|                             .settable(ledHandler); |                             .settable(ledHandler); | ||||||
|  |   buttonNode.advertise(NODE_BUTTON).setName("Button pressed") | ||||||
|  |                             .setDatatype("integer"); | ||||||
|  |  | ||||||
|   strip.begin(); |   strip.begin(); | ||||||
|   /* activate I2C for BOSCH sensor */ |   /* activate I2C for BOSCH sensor */ | ||||||
| @@ -512,19 +532,37 @@ void loop() | |||||||
|   } |   } | ||||||
|   /* use the pin, receiving the soft serial additionally as button */ |   /* use the pin, receiving the soft serial additionally as button */ | ||||||
|   if (digitalRead(GPIO_BUTTON) == LOW) { |   if (digitalRead(GPIO_BUTTON) == LOW) { | ||||||
|     mButtonPressed++; |     if ((millis() - mLastButtonAction) > BUTTON_CHECK_INTERVALL) { | ||||||
|  |       mButtonPressed++; | ||||||
|  |     } | ||||||
|  |     if (mButtonPressed > BUTTON_MIN_ACTION_CYCLE) { | ||||||
|  |       digitalWrite(WITTY_RGB_R, HIGH); | ||||||
|  |       digitalWrite(WITTY_RGB_G, LOW); | ||||||
|  |       digitalWrite(WITTY_RGB_B, LOW); | ||||||
|  |       strip.fill(strip.Color(0,0,0)); | ||||||
|  |       strip.setPixelColor(0, strip.Color((mButtonPressed % 100),0,0)); | ||||||
|  |       strip.setPixelColor(1, strip.Color((mButtonPressed / 100),0,0)); | ||||||
|  |       strip.setPixelColor(2, strip.Color((mButtonPressed / 100),0,0)); | ||||||
|  |       strip.show(); | ||||||
|  |     } | ||||||
|   } else { |   } else { | ||||||
|     mButtonPressed=0U; |     mButtonPressed=0U; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (mButtonPressed > 10000U) { |   if (mButtonPressed > BUTTON_MAX_CYCLE) {     | ||||||
|     mButtonPressed=0U; |     mButtonPressed = (BUTTON_MAX_CYCLE -1); | ||||||
|     if (SPIFFS.exists("/homie/config.json")) { |     if (SPIFFS.exists("/homie/config.json")) { | ||||||
|  |       strip.fill(strip.Color(0,128,0)); | ||||||
|  |       strip.show(); | ||||||
|       printf("Resetting config\r\n"); |       printf("Resetting config\r\n"); | ||||||
|       SPIFFS.remove("/homie/config.json"); |       SPIFFS.remove("/homie/config.json"); | ||||||
|       SPIFFS.end(); |       SPIFFS.end(); | ||||||
|  |       delay(50); | ||||||
|  |       Homie.reboot(); | ||||||
|     } else { |     } else { | ||||||
|       printf("No config present\r\n"); |       printf("No config present\r\n"); | ||||||
|  |       strip.fill(strip.Color(0,0,128)); | ||||||
|  |       strip.show(); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user