Browse Source

New influx lib

master
José Valdiviesso 1 year ago
parent
commit
74eb332790
  1. 6
      .gitmodules
  2. 50
      ESP32-SolarPowerMonitor.ino
  3. 2
      README.md
  4. 7
      config_example.h
  5. 1
      src/ESP_influxdb
  6. 1
      src/InfluxDB-Client-for-Arduino

6
.gitmodules

@ -1,6 +1,6 @@
[submodule "src/EmonLib"]
path = src/EmonLib
url = https://github.com/openenergymonitor/EmonLib.git
[submodule "src/ESP_influxdb"]
path = src/ESP_influxdb
url = https://github.com/hwwong/ESP_influxdb.git
[submodule "src/InfluxDB-Client-for-Arduino"]
path = src/InfluxDB-Client-for-Arduino
url = https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino.git

50
ESP32-SolarPowerMonitor.ino

@ -1,6 +1,7 @@
#include <Arduino.h>
#include "WiFi.h"
#include "src/ESP_influxdb/ESPinfluxdb.h"
#include "WiFiMulti.h"
#include "src/InfluxDB-Client-for-Arduino/src/InfluxDbClient.h"
#include "src/EmonLib/EmonLib.h"
#include "config.h"
@ -8,39 +9,42 @@
#define Vpin 33
EnergyMonitor emon1; // Create an instance
WiFiMulti WiFiMulti;
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_DB_NAME);
void ConnectToWiFi(){
// Data point
Point sensor("solar_status");
void ConnectToWiFiMulti(){
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, WiFiPassword);
Serial.print("Connecting to "); Serial.println(SSID);
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED)
{
Serial.print('.');
delay(500);
if ((++i % 16) == 0)
{
Serial.println(F(" still trying to connect"));
}
WiFiMulti.addAP(SSID, WiFiPassword);
Serial.println("Connecting Wifi...");
while(WiFiMulti.run() != WL_CONNECTED) {
delay(100);
}
Serial.print(F("Connected. My IP address is: "));
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
void ConnectToInflux(){
while (influxdb.opendb(DATABASE)!=DB_SUCCESS) {
Serial.println("Opend database failed");
delay(10000);
// Add constant tags - only once
sensor.addTag("Phase", "Solar 1");
// Check server connection
if (client.validateConnection()) {
Serial.print("Connected to InfluxDB: ");
Serial.println(client.getServerUrl());
} else {
Serial.print("InfluxDB connection failed: ");
Serial.println(client.getLastErrorMessage());
}
}
void setup() {
Serial.begin(115200);
ConnectToWiFi();
ConnectToWiFiMulti();
ConnectToInflux();
analogReadResolution(ADC_BITS);
emon1.voltage(Vpin, 234.26, 1.7); // Voltage: input pin, calibration, phase_shift
@ -50,6 +54,8 @@ void setup() {
void loop() {
emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
delay(5000);
//influx to be implemented...
Point sensor("wifi_status");
}

2
README.md

@ -12,4 +12,4 @@ My take on a power measurement device using a ESP32, ACS712 Current Sensor & AC
### Libraries used
- [openenergymonitor/EmonLib](https://github.com/openenergymonitor/EmonLib) - for sensor measuring
- [hwwong/ESP_influxdb](https://github.com/hwwong/ESP_influxdb) - for influxdb connection
- [tobiasschuerg/InfluxDB-Client-for-Arduino](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino) - for influxdb connection

7
config_example.h

@ -1,9 +1,6 @@
const char *SSID = "ssid";
const char *WiFiPassword = "password";
const char *INFLUXDB_HOST = "host_IP";
const uint16_t INFLUXDB_PORT = 8086;
const char *INFLUXDB_URL = "http://ip:8086";
const char *DATABASE = "dbname";
const char *DB_USER = "dbuser";
const char *DB_PASSWORD = "dbpassword";
const char *INFLUXDB_DB_NAME = "dbname";

1
src/ESP_influxdb

@ -1 +0,0 @@
Subproject commit 4c835806326e96784411272c8c35b61b967455c4

1
src/InfluxDB-Client-for-Arduino

@ -0,0 +1 @@
Subproject commit 66ed5d031caab6953cc79b407a4b49d33b1126dc
Loading…
Cancel
Save