Permalink
Browse files

Some tidying up of code

  • Loading branch information...
dpoulson committed Oct 16, 2018
1 parent 26d77b2 commit 6cd82f921e2bb1636776f42ce9d65cfebf8e2942
Showing with 21 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +4 −12 EPSolar.ino
  3. +4 −0 README.md
  4. +12 −0 config.h-default
View
@@ -0,0 +1 @@
config.h
View
@@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
@@ -31,14 +32,6 @@ float batt_type, batt_cap, batt_highdisc, batt_chargelimit, batt_overvoltrecon,
float batt_lowvoltrecon, batt_undervoltrecon, batt_undervoltwarn, batt_lowvoltdisc;
uint8_t result;
const char* ssid = "60 Chequers Avenue AP1";
const char* password = "trial3211";
const char* mqtt_server = "192.168.6.46";
#define OTA_HOSTNAME "SOLAR-CHARGE-MONITOR-1"
#define EPSOLAR_DEVICE_ID 1
WiFiClient espClient;
PubSubClient client(espClient);
@@ -50,6 +43,7 @@ SimpleTimer timer;
char buf[10];
String value;
char mptt_location[16];
// tracer requires no handshaking
void preTransmission() {}
@@ -123,10 +117,9 @@ void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("EPSolar1")) {
if (client.connect("EPSolar1", mqtt_user, mqtt_pass)) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("EPSolar/1/loop1", "Reconnect");
} else {
// Wait 5 seconds before retrying
delay(5000);
@@ -142,10 +135,9 @@ void AddressRegistry_3100() {
result = node.readInputRegisters(0x3100, 10);
if (result == node.ku8MBSuccess)
{
client.publish("EPSolar/1/loop1", "result");
ctemp = (long)node.getResponseBuffer(0x11) / 100.0f;
dtostrf(ctemp, 2, 3, buf );
//mqtt_location = MQTT_ROOT + "/" + EPSOLAR_DEVICE_ID + "/ctemp";
client.publish("EPSolar/1/ctemp", buf);
bvoltage = (long)node.getResponseBuffer(0x04) / 100.0f;
View
@@ -10,6 +10,10 @@ By default, this will write to queues under:
/EPSolar/\<device ID\>/\<stat\>
# Usage
Copy the config.h-default to config.h and edit the parameters. If you have more than one solar module, then you can adjust the ID number in each client.publish line. Plans are to at some point make this a single variable, but that is in testing.
# Incorporating into OpenHAB
You will need the MQTT binding installed and configured to connect to the same MQTT instance. Once that is done, you can create an items file similar to this:
View
@@ -0,0 +1,12 @@
const char* ssid = "your_ssid";
const char* password = "your_wifi_password";
const char* mqtt_server = "your_mqtt_server";
const char* mqtt_user = "mqtt_user";
const char* mqtt_pass = "mqtt_pass";
#define OTA_HOSTNAME "SOLAR-CHARGE-MONITOR-1"
#define EPSOLAR_DEVICE_ID 1
#define MQTT_ROOT "EPSolar"

0 comments on commit 6cd82f9

Please sign in to comment.