@ -42,14 +42,14 @@
/* CHANGE THESE VALUES TO CUSTOMIZE DATA LOGGER */
/* CHANGE THESE VALUES TO CUSTOMIZE DATA LOGGER */
# define CLIENT_ID "MeesElectronics" // Our MQTT client ID
# define CLIENT_ID "MeesElectronics" // Our MQTT client ID
# define CLIENT_TOPIC "energy / solar" // Name of the topic we publish
# define CLIENT_TOPIC "distributioncabinet / energy / solar" // Name of the topic we publish
//IPAddress IP_MQTT_broker(192, 168, 89, 10); // IP address of the MQTT broker
//IPAddress IP_MQTT_broker(192, 168, 89, 10); // IP address of the MQTT broker
//String string_ip_mqtt_broker = "192.168.88.10";
//String string_ip_mqtt_broker = "192.168.88.10";
char IP_string_MQTT_broker [ 20 ] = " 192.168.88.11 " ;
char IP_string_MQTT_broker [ 20 ] = " 192.168.88.11 " ;
uint16_t MQTT_port = 1884 ;
uint16_t MQTT_port = 1883 ;
IPAddress IP_MQTT_broker ;
IPAddress IP_MQTT_broker ;
# define PULSES_PER_KWH 5 00 // 500 pulses from the energy meter is one kWh
# define PULSES_PER_KWH 10 00 // 500 pulses from the energy meter is one kWh
/* END USER DEFINABLE VALUES */
/* END USER DEFINABLE VALUES */
uint8_t mac [ 6 ] = { MACADDRESS } ;
uint8_t mac [ 6 ] = { MACADDRESS } ;
@ -63,7 +63,7 @@ EthernetClient ethClient;
PubSubClient mqttClient ;
PubSubClient mqttClient ;
# define PULSES_PER_WH 1000 / PULSES_PER_KWH // Calculates how many pulses corresponds to a Wh
# define PULSES_PER_WH 1000 / PULSES_PER_KWH // Calculates how many pulses corresponds to a Wh
# define INTERVAL 10000 // 1 0 sec delay between MQTT publishings
# define INTERVAL 60000 // 6 0 sec delay between MQTT publishings
long previousMillis ;
long previousMillis ;
char numberArray [ 20 ] ;
char numberArray [ 20 ] ;
@ -71,6 +71,8 @@ uint32_t PulseCount=0; // This variable holds the pul
uint32_t EnergyReading = 0 ; // This variable holds the number of Watt-hours
uint32_t EnergyReading = 0 ; // This variable holds the number of Watt-hours
uint32_t stored_kwh_count = 0 ; // Counted whole kWh value sored in EEPROM
uint32_t stored_kwh_count = 0 ; // Counted whole kWh value sored in EEPROM
# define LED 9
void onDetectInterrupt ( )
void onDetectInterrupt ( )
{
{
// The Arduino calls this function when it detects a falling edge on pin 2.
// The Arduino calls this function when it detects a falling edge on pin 2.
@ -118,6 +120,9 @@ void setup() {
pinMode ( 2 , INPUT_PULLUP ) ;
pinMode ( 2 , INPUT_PULLUP ) ;
attachInterrupt ( digitalPinToInterrupt ( 2 ) , onDetectInterrupt , FALLING ) ;
attachInterrupt ( digitalPinToInterrupt ( 2 ) , onDetectInterrupt , FALLING ) ;
pinMode ( LED , OUTPUT ) ;
digitalWrite ( LED , HIGH ) ;
// initialize the ethernet device
// initialize the ethernet device
//Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
//Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
Serial . print ( F ( " Configuring ethernet... " ) ) ;
Serial . print ( F ( " Configuring ethernet... " ) ) ;
@ -240,6 +245,11 @@ void loop() {
else
else
{
{
client . write ( " ? " , 1 ) ;
client . write ( " ? " , 1 ) ;
//client.write("?\n",2);
//client.write(": <IP> sets ip of broker.\n",26);
//client.write("P <port> set port op broker.\n",29);
//client.write("I prints ip and port of broker.\n",32);
//client.write("S saves settings to EEPROM.,27");
Serial . println ( F ( " ? " ) ) ;
Serial . println ( F ( " ? " ) ) ;
}
}
client . write ( " \n " , 1 ) ;
client . write ( " \n " , 1 ) ;
@ -258,6 +268,11 @@ void loop() {
}
}
mqttClient . loop ( ) ;
mqttClient . loop ( ) ;
readEnergymeter ( ) ;
readEnergymeter ( ) ;
if ( digitalRead ( 2 ) )
digitalWrite ( LED , HIGH ) ;
else
digitalWrite ( LED , LOW ) ;
}
}
void sendData ( ) {
void sendData ( ) {