diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a80acd..dc5e66e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.1.2] - 2020-04-16 +### Changed +- Updated the docs +- Read (and in debug mode print out) sensor values even without an active wifi connection + ## [2.1.1] - 2020-04-15 ### Changed - Fixed MQTT topic to include the whole OBIS identifier diff --git a/README.md b/README.md index 95f1463..b056555 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,44 @@ static const SensorConfig SENSOR_CONFIGS[] = { WiFi and MQTT are configured via the web interface provided by [IotWebConf](https://github.com/prampec/IotWebConf) and which can be reached after joining the WiFi network named SMLReader and heading to http://192.168.4.1. If the device has already been configured, the web interface can be reached via the IP address obtained from your local network's DHCP server. +--- + +### Flashing + +There are several ways to flash SMLReader to your ESP8266. +I personally prefer the docker way using my dockerized version of esptool.py. + +#### IDE + +You should be able to use your preferred IDE to build and flash SMLReader if you take care of the dependencies and the build flags configured in the `platform.io` file. +I strongly recommend using PlatformIO as it takes care of that itself. + +#### esptool.py + +###### Flashing +```bash +docker run -it --device /dev/ttyUSB0 -v $(pwd):/src --rm mruettgers/esptool ash -c "esptool --port /dev/ttyUSB0 write_flash -fm dout 0x00000 /src/smlreader.bin" +``` + +Of couse you can flash the image without the use of docker by directily utilizing your local copy of esptool.py: + +```bash +esptool.py --port /dev/ttyUSB0 write_flash -fm dout 0x00000 ./smlreader.bin +``` + +###### Flashing with serial port monitor +```bash +docker run -it --device /dev/ttyUSB0 -v $(pwd):/src --rm mruettgers/esptool ash -c "esptool --port /dev/ttyUSB0 write_flash -fm dout 0x00000 /src/smlreader.bin && miniterm.py /dev/ttyUSB0 115200" +``` + +###### Serial port monitor +```bash +docker run -it --device /dev/ttyUSB0 -v $(pwd):/src --rm mruettgers/esptool ash -c "miniterm.py /dev/ttyUSB0 115200" +``` + +--- + + ### Running If everything is configured properly and running with a sensor in place, SMLReader will publish the metrics and values received from the meter to the configured MQTT broker: @@ -95,6 +133,9 @@ smartmeter/mains/sensor/3/obis/1-0:2.8.2*255/value 0.0 smartmeter/mains/sensor/3/obis/1-0:16.7.0*255/value 451.2 ``` +--- + + ### Debugging Verbose serial logging can be enabled by setting `SERIAL_DEBUG_VERBOSE=true` in the `platformio.ini` file. diff --git a/src/Sensor.h b/src/Sensor.h index 28d1f5c..3d6726c 100644 --- a/src/Sensor.h +++ b/src/Sensor.h @@ -42,12 +42,10 @@ class Sensor this->serial->enableTx(false); this->serial->enableRx(true); DEBUG("Initialized sensor %s.", this->config->name); - } - void init() - { - DEBUG("Initializing state of sensor %s...", this->config->name); + this->init_state(); } + void loop() { this->run_current_state(); diff --git a/src/config.h b/src/config.h index 7d71021..7694e1e 100644 --- a/src/config.h +++ b/src/config.h @@ -4,7 +4,7 @@ #include "Arduino.h" #include "Sensor.h" -const char *VERSION = "2.1.1"; +const char *VERSION = "2.1.2"; // Modifying the config version will probably cause a loss of the existig configuration. // Be careful! diff --git a/src/main.cpp b/src/main.cpp index 7bc848f..b6a18fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,7 +40,9 @@ void process_message(byte *buffer, size_t len, Sensor *sensor) DEBUG_SML_FILE(file); - publisher.publish(sensor, file); + if (connected) { + publisher.publish(sensor, file); + } // free the malloc'd memory sml_file_free(file); @@ -107,8 +109,10 @@ void setup() void loop() { // Publisher - publisher.loop(); - yield(); + if (connected) { + publisher.loop(); + yield(); + } if (needReset) { @@ -117,12 +121,10 @@ void loop() delay(1000); ESP.restart(); } - if (connected) - { - // Execute sensor state machines - for (std::list::iterator it = sensors->begin(); it != sensors->end(); ++it){ - (*it)->loop(); - } + + // Execute sensor state machines + for (std::list::iterator it = sensors->begin(); it != sensors->end(); ++it){ + (*it)->loop(); } iotWebConf.doLoop(); yield(); @@ -139,9 +141,4 @@ void wifiConnected() DEBUG("WiFi connection established."); connected = true; publisher.connect(); - - // Initialize sensors - for (std::list::iterator it = sensors->begin(); it != sensors->end(); ++it){ - (*it)->init(); - } }