All,
Up and running for 2 weeks. (Issues and all...) Being frustrated that WM had to be running to get data to thingspeak, or to mobile app, monitoring new baby while it's crying.
So, I connected an little Aduino (needed for more temp monitoring with DS18B20's. Still TODO.)
Receiving UDP from Batrium to Arduino and bumping it to thingspeak. Then easily available on mobile. Almost as cheap as chips, but cheaper than chips and bear.
Some links:
THis chap got me going in LinqPad to get UDP understanding.
https://forums.aeva.asn.au/viewtopic.php?f=64&t=5768
Daromer link to Batrium UDP packet file/spec (I think. Found it somewhere.)
https://github.com/Batrium/WatchMon.../WatchMon Wifi UDP protocol sw1.0.30 v1.0.pdf
Many mobile apps available reading your thingspeak data.
POC working posting 2 fields to thingspeak. Very simple code to get it working. No local storage, just bumping data forward.
Adruino can be close to your pack, or anywhere on the network. Quite a lot of benefits and uses.
---------------------------------------------
Up and running for 2 weeks. (Issues and all...) Being frustrated that WM had to be running to get data to thingspeak, or to mobile app, monitoring new baby while it's crying.
So, I connected an little Aduino (needed for more temp monitoring with DS18B20's. Still TODO.)
Receiving UDP from Batrium to Arduino and bumping it to thingspeak. Then easily available on mobile. Almost as cheap as chips, but cheaper than chips and bear.
Some links:
THis chap got me going in LinqPad to get UDP understanding.
https://forums.aeva.asn.au/viewtopic.php?f=64&t=5768
Daromer link to Batrium UDP packet file/spec (I think. Found it somewhere.)
https://github.com/Batrium/WatchMon.../WatchMon Wifi UDP protocol sw1.0.30 v1.0.pdf
Many mobile apps available reading your thingspeak data.
POC working posting 2 fields to thingspeak. Very simple code to get it working. No local storage, just bumping data forward.
Adruino can be close to your pack, or anywhere on the network. Quite a lot of benefits and uses.
---------------------------------------------
Code:
#include <WiFi.h>
#include <WiFiUdp.h>
#include <ThingSpeak.h>
const char* ssid = "YOUR SSID";
const char* password = "YOUR WIFI PWD";
const int udpPort = 18542; //Port for receiving Batrium messages
unsigned long myChannelNumber = 1234566;//Your thingspeak channel #
const char * myWriteAPIKey = "abdde....";//your thingspeak write api key
WiFiServer server(80); //For later. Cann then access on local wifi network via browser. WIP.
//create UDP instance
WiFiUDP udp;
WiFiClient client;
void setup()
{
Serial.begin(115200);
pinMode(2, OUTPUT); // set the LED pin mode
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
udp.begin(udpPort);
ThingSpeak.begin(client);
}
void loop(){
Fetch();
delay(60000);
}
float cell_voltsMin;
float cell_voltsMax;
float cell_voltsAvg; //3
uint8_t cell_bypass_cnt;//1
float shunt_volts;//4
float shunt_amps;//5
float shunt_power;//6
float shunt_soc; //8
float shunt_cap_to_full;//7
float shunt_cap_to_empty;//2
void Fetch()
{
uint16_t tmp16;
uint8_t tmp8;
bool hasSoc=false;
bool hasVolts=false;
//receive response from server, it will be HELLO WORLD
while(hasSoc == false || hasVolts == false)
{
udp.parsePacket();
uint8_t buffer[1024] = "";
if(udp.read(buffer, 1024) > 0)
{
if(buffer[1]==51 && buffer[2] ==63 && hasSoc == false)
{
Serial.println("Reading 5163");
memcpy(&shunt_cap_to_full, &buffer[34], sizeof(float));
shunt_cap_to_full = shunt_cap_to_full / 1000;
memcpy(&shunt_cap_to_empty, &buffer[38], sizeof(float));
shunt_cap_to_empty = shunt_cap_to_empty / 1000;
memcpy(&tmp8, &buffer[32], sizeof(uint8_t));
shunt_soc = (float(tmp8) / 2)-5;
Serial.println("shunt_soc x: " + String(tmp8) + " shunt_soc:" + String(shunt_soc));
hasSoc = true;
}
else if(buffer[1]==50 && buffer[2] ==62 && hasVolts == false)
{
Serial.println("Reading 5062");
memcpy(&cell_bypass_cnt, &buffer[33], sizeof(uint8_t));
memcpy(&tmp16, &buffer[8], sizeof(uint16_t));
cell_voltsMin = float(tmp16) / 100;
memcpy(&tmp16, &buffer[10], sizeof(uint16_t));
cell_voltsMax = float(tmp16) / 100;
memcpy(&tmp16, &buffer[28], sizeof(uint16_t));
cell_voltsAvg = float(tmp16) / 1000;
memcpy(&tmp16, &buffer[40], sizeof(uint16_t));
shunt_volts = float(tmp16) / 100;
memcpy(&shunt_amps, &buffer[42], sizeof(float));
shunt_amps = shunt_amps / 1000;
memcpy(&shunt_power, &buffer[46], sizeof(float));
shunt_power = shunt_power ;
hasVolts = true;
}
}
}
SendToSpeak();
}
void SendToSpeak()
{
/* float cell_voltsAvg; //3
uint8_t cell_bypass_cnt;//1
float shunt_volts;//4
float shunt_amps;//5
float shunt_power;//6
float shunt_soc; //8
float shunt_cap_to_full;//7
float shunt_cap_to_empty;//2
*/
// set the fields with the values
ThingSpeak.setField(1, cell_bypass_cnt);
ThingSpeak.setField(2, shunt_cap_to_empty);
ThingSpeak.setField(3, cell_voltsAvg);
ThingSpeak.setField(4, shunt_volts);
ThingSpeak.setField(5, shunt_amps);
ThingSpeak.setField(6, shunt_power);
ThingSpeak.setField(7, shunt_cap_to_full);
ThingSpeak.setField(8, shunt_soc);
// set the status
// ThingSpeak.setStatus("CZ Updating status");
// write to the ThingSpeak channel
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
}