restructured code to prepare MQTT
This commit is contained in:
parent
da0a75445d
commit
e52764751c
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
SCT-013 Sensor - Power meassurement, based on Thomas Edlinger's code for "www.edistechlab.com"
|
||||
Required libraries (Tools -> manage libraries)
|
||||
- EmonLib libary V1.1.0 by OpenEnergyMonitor
|
||||
Based on EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
|
||||
*/
|
||||
|
||||
#include "EmonLib.h"
|
||||
EnergyMonitor emon1;
|
||||
const byte current1Pin = A1; // ADC-PIN
|
||||
const byte voltage = 230; // Power voltage in Europe = 230 V
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
analogReadResolution(ADC_BITS); // activate 12 Bit resolution for our ESP32
|
||||
emon1.current(current1Pin, 8); // Pin and Calibration
|
||||
}
|
||||
|
||||
void loop() {
|
||||
double Irms = emon1.calcIrms(1480);
|
||||
Serial.print(Irms*voltage);
|
||||
Serial.print(" Watt - ");
|
||||
Serial.print(Irms);
|
||||
Serial.println(" Ampere");
|
||||
delay(1000);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
// Replace with your network credentials
|
||||
#define secrect_ssid "your_ssid"
|
||||
#define secret_password "your_password"
|
||||
#define mqttServer = "m16.cloudmqtt.com"
|
||||
#define mqttPort = 12595
|
|
@ -68,7 +68,7 @@ See the Fritzing file for [details](./energy-monitor/energy-monitor.fzz).
|
|||
|
||||
Start with a simple code that just prints the values. The code is quite simple, as we can use the existing *[EmonLib libary V1.1.0 by OpenEnergyMonitor](https://docs.openenergymonitor.org/electricity-monitoring/ct-sensors/)*.
|
||||
|
||||
[Check out the small amount of code to print the values to serial out.](https://code.curious.bio/curious.bio/iot-platform/src/commit/ecf0b3ee63c9d3d49bcf32a7da9bde64a6a62c28/software/firmware/energy-montior/energy-monitor/energy-monitor.ino) This piece of code is based on on Thomas Edlinger's code for [Edi's Tech Lab](https://www.edistechlab.com).
|
||||
[Check out the small amount of code to print the values to serial out.](./01-energy-monitor-serial-out/) This piece of code is based on on Thomas Edlinger's code for [Edi's Tech Lab](https://www.edistechlab.com).
|
||||
|
||||
The only interesting part is this line:
|
||||
|
||||
|
@ -90,8 +90,16 @@ The code just prints the current power consumption to serial out:
|
|||
```
|
||||
#### Post to MQTT
|
||||
|
||||
// TODO: Continue here
|
||||
##### Credentials
|
||||
|
||||
To connect to your wifi and access your MQTT server you have to add this to an `environment` header file:
|
||||
|
||||
```C
|
||||
#define secrect_ssid "your_ssid"
|
||||
#define secret_password "your_password"
|
||||
#define mqttServer = "m16.cloudmqtt.com"
|
||||
#define mqttPort = 12595
|
||||
```
|
||||
|
||||
## Links
|
||||
|
||||
|
|
Loading…
Reference in a new issue