Skip to content

Commit

Permalink
Added RS485 RX/TX pins to Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan ten Hove committed Jun 15, 2017
1 parent ca8d65e commit cbf438f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
7 changes: 4 additions & 3 deletions GoodWeCommunicator.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#include "GoodWeCommunicator.h"


GoodWeCommunicator::GoodWeCommunicator(int receivePin, int transmitPin, bool inDebug)
GoodWeCommunicator::GoodWeCommunicator(SettingsManager * settingsManager, bool inDebug)
{
auto settings = settingsManager->GetSettings();
//create the software serial on the custom pins so we can use the hardware serial for debug comms.
goodweSerial = new SoftwareSerial(receivePin, transmitPin, false, BufferSize); // (RX, TX. inverted, buffer)
goodweSerial = new SoftwareSerial(settings->RS485Rx, settings->RS485Tx, false, BufferSize); // (RX, TX. inverted, buffer)
debugMode = inDebug;
}

void GoodWeCommunicator::start()
{
//start the software serial
goodweSerial->begin(9600);
goodweSerial->begin(9600); //inverter fixed baud rate

//set the fixed part of our buffer
headerBuffer[0] = 0xAA;
Expand Down
3 changes: 2 additions & 1 deletion GoodWeCommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <vector>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include "SettingsManager.h"

#define GOODWE_COMMS_ADDRES 0xAB
#define PACKET_TIMEOUT 500 //0.5 sec packet timeout
Expand Down Expand Up @@ -54,7 +55,7 @@ class GoodWeCommunicator
float eDay = 0.0;
};

GoodWeCommunicator(int receivePin, int transmitPin, bool debugMode = false);
GoodWeCommunicator(SettingsManager * settingsManager, bool debugMode = false);
void start();
void stop();
void handle();
Expand Down
5 changes: 4 additions & 1 deletion GoodWeLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "Settings.h" //change and then rename Settings.example.h to Settings.h to compile


GoodWeCommunicator goodweComms(D1, D2, true);
SettingsManager settingsManager;
GoodWeCommunicator goodweComms(&settingsManager, true);
MQTTPublisher mqqtPublisher(&settingsManager, &goodweComms, true);
PVOutputPublisher pvoutputPublisher(&settingsManager, &goodweComms, true);
WiFiUDP ntpUDP;
Expand All @@ -40,6 +40,9 @@ void setup()
settings->wifiSSID = WIFI_SSID;
settings->wifiPassword = WIFI_PASSWORD;
settings->timezone = TIMEZONE;
settings->RS485Rx = RS485_RX;
settings->RS485Tx = RS485_TX;


/* add setup code here */
Serial.begin(115200);
Expand Down
5 changes: 5 additions & 0 deletions Settings.example.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@
//timezone offset in hours (amsterdam is +2 in summertime). Used for posting to pvoutput
#define TIMEZONE 2

//rs485 receive pin
#define RS485_RX D1

//rs485 transmit pin
#define RS485_TX D2
10 changes: 7 additions & 3 deletions SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ class SettingsManager
int mqttQuickUpdateInterval;
int mqttRegularUpdateInterval;


int timezone;

//pvoutput settings
String pvoutputApiKey;
String pvoutputSystemId;
int pvoutputUpdateInterval;

//wifi settings
String wifiSSID;
String wifiPassword;

//general settings
int RS485Rx =D1; //default set because added later
int RS485Tx =D2;
int timezone;

};
SettingsManager();
~SettingsManager();
Expand Down

0 comments on commit cbf438f

Please sign in to comment.