That's awesome. Thanks, wallaby. I will test the code tomorrow. I'm going through a router.
As of now, I have the Uno controlling a solar water heating system and sending temperature data to emoncms.org for visualization. I'd like to do the same with the data from two Classic charge controllers. If I can manage that, I would also like to connect to two Magnum inverters and grab some data. I looked at the Magnum networking protocols (attached), and one inverter is the master, and the other a slave. They don't have a register map, and it seems that-the inverters at least-just send out their data every 100ms. I'm not sure how much that will complicate things.
In addition to the two MS-PAE inverters, I have an ME-BMK battery monitor, and an auto gen start (AGS) module - all connected to an ME-RTR router. I'd like to get data for AC voltage/current going in and out of the inverters, DC voltage/current out of the inverts , the SOC of the batteries (ME-BMK), the gen set run time (AGS), and days since last run (AGS).
I'm posting my code for the solar thermal controller below. It is working, but probably ain't pretty - you might want to put your gumboots on before diving in. If I can figure out the Classic bit, I will try to add that to the solar thermal code. If I make it that far, I'll try for the Magnum data. It could be a tall order for me.
Thanks again for your help. If you have any other thoughts, I'd be glad to hear 'em.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
#include <dht.h>
#include <Adafruit_MAX31855.h>
//*****Set thermocouple pins and declare thermocouple breakout board***********
// Thermocouple pins
int thermoDO = 7;
int thermoCS = 6;
int thermoCLK = 5;
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
//*****Set variables for pump and fan operation***********
int pump=0;
int fan=0;
//*****DHT Temp/Humidity sensor setup******
dht DHT;
#define DHT21_PIN 2
// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// fill in an available IP address on your network here,
// for manual configuration:
//IPAddress ip(Myip);
// fill in your Domain Name Server address here:
//IPAddress myDns(1,1,1,1);
// initialize the library instance:
EthernetClient client;
char server[] = "emoncms.org";
String apikey = "Myapi"; //api key
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 5*1000; // delay between updates, in milliseconds
//Sets DS18b20 temperature probes to pin 3
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// DS18b20 Addresses where found manually using temperature_search (emontx firmware)
DeviceAddress address_outside = { 0x28, 0x64, 0x84, 0x04, 0x05, 0x00, 0x00, 0xEE };
DeviceAddress address_tank_bottom = { 0x28, 0x11, 0xBF, 0x56, 0x05, 0x00, 0x00, 0xB6 };
DeviceAddress address_tank_top = { 0x28, 0x05, 0x0F, 0x56, 0x05, 0x00, 0x00, 0x7E };
void setup() {
// start serial port:
Serial.begin(9600);
// give the ethernet module time to boot up:
delay(1000);
// start the Ethernet connection using a fixed IP address and DNS server:
Ethernet.begin(mac);
// print the Ethernet board/shield's IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
//initiate temp sensors
sensors.begin();
// Relay control digital output on pins 8 & 9
pinMode(8,OUTPUT); // pump relay
pinMode(9,OUTPUT); // fan relay
}
void loop() {
delay(5000);
// get humidity/temp data (sensor AM2301 (DHT21))
Serial.print("DHT21, \t");
int chk = DHT.read21(DHT21_PIN);
switch (chk)
{
case DHTLIB_OK:
//Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("DHT Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("DHT Time out error,\t");
break;
default:
Serial.print("DHT Unknown error,\t");
break;
}
int Room_Temp = 1.8*(DHT.temperature) + 32;
int RH = (DHT.humidity);
// get DS18b20 temperature probe data
sensors.requestTemperatures();
int Outside_Temp = sensors.getTempF(address_outside);
int Tank_Bottom = sensors.getTempF(address_tank_bottom);
int Tank_Top = sensors.getTempF(address_tank_top);
int Collector_Temp = thermocouple.readFarenheit();
int diff = Collector_Temp - Tank_Bottom;
runPump(Collector_Temp, Tank_Bottom, diff);
runFan(RH);
debug(Collector_Temp, Tank_Top, Tank_Bottom, Outside_Temp, Room_Temp, RH, pump, fan, diff);
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
httpDataIn();
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
httpRequest(Collector_Temp, Tank_Top, Tank_Bottom, Outside_Temp, Room_Temp, RH, pump, fan, diff);
}
// store the state of the connection for next time through the loop:
lastConnected = client.connected();
}
// this method makes a HTTP connection to the server:
void httpRequest(int Collector_Temp, int Tank_Top, int Tank_Bottom,int Outside_Temp, int Room_Temp, int RH, int pump, int fan, int diff) {
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP PUT request:
client.print("GET /input/post.json?json={outside_temp");
client.print(":");
client.print(Outside_Temp);
client.print(",Tank_Bottom_Temp:");
client.print(Tank_Bottom);
client.print(",Tank_Top_Temp:");
client.print(Tank_Top);
client.print(",Room_Temp:");
client.print(Room_Temp);
client.print(",RH:");
client.print(RH);
client.print(",Collector_Temp:");
client.print(Collector_Temp);
client.print(",Temp_differential:");
client.print(diff);
client.print(",Pump:");
client.print(pump);
client.print(",Fan:");
client.print(fan);
client.print("}&apikey=");
client.print(apikey);
client.println(" HTTP/1.1");
client.println("Host: emoncms.org");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
Serial.println("disconnecting.");
client.stop();
}
}
void runPump(int Collector_Temp, int Tank_Bottom, int diff)
{
// If Collector is 40F above the bottom of the cylinder turn pump on
if (diff > 40.0) pump = 1;
// If Collector is less than 25F above the bottom of the cylinder turn pump off
if (diff < 25.0) pump = 0;
// Check to stop overheating of cylinder
if (Tank_Bottom > 130) pump = 0;
if (pump) digitalWrite(8,HIGH); else digitalWrite(8,LOW);
}
void runFan(int RH)
{
// if humidity > 60% fan turns on
if (RH > 60) fan = 1;
//if humidity drops back below 50% fan turns off
if (RH < 50) fan = 0;
if (fan) digitalWrite(9, HIGH); else digitalWrite(9,LOW);
//print RH value
Serial.print("Rel. Humidity = ");
Serial.println(RH);
}
void httpDataIn(){
while (client.available()) {
char c = client.read();
Serial.print(c);}
}
void debug(int Collector_Temp, int Tank_Top, int Tank_Bottom,int Outside_Temp, int Room_Temp, int RH, int pump, int fan, int diff)
{
//print data to serial bus
if (isnan(Collector_Temp)) {
Serial.println("Something wrong with thermocouple!");
} else {
Serial.print("Collector Temp = ");
Serial.println(Collector_Temp);
}
Serial.print("Tank_Bottom Temp = ");
Serial.println(Tank_Bottom);
Serial.print("Tank_Top Temp = ");
Serial.println(Tank_Top);
Serial.print("Temperature Differential = ");
Serial.println(diff);
Serial.print("Outside Temp = ");
Serial.println(Outside_Temp);
Serial.print("Room Temp = ");
Serial.println(Room_Temp);
Serial.print("Rel. Humidity = ");
Serial.println(RH);
Serial.print("Pump state = ");
Serial.println(pump);
Serial.print("fan state = ");
Serial.println(fan);
Serial.println();
}
Magnum-Networking-Communications-Protocol-(2009-10-15).pdf (62 KB)