vespapierre:
I would like to have sd logging in case going offline..
That's fine, I am doing the same thing, but that's not the same as sending the SD file to cosm.
.all I have to find where and how to put that sd codes...Sd involved in the concept...
The code below is about 36k. I am currently in the throes of moving to Mega 2560. While I'm sure this can be written more elegantly, it probably won't save enough to squeeze into a Uno.
/*
/*From cosm library example and lifts from a lot of others
particularly from Stanley in Kuala Lumpur.
Use your own DS18B20 addresses, keys etc.
*/
#include <LiquidCrystal.h>
#include <SD.h>
#include <string.h>
#include "RTClib.h"
RTC_DS1307 RTC;
File myFile;
char filename[] = "00000000.CSV";
#include "Wire.h"
#define DS1307_ADDRESS 0x68
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Cosm.h>
byte InThermo[8] = {
0x28, 0x69, 0xC2, 0xB0, 0x03, 0x00, 0x00, 0X9F};
byte OutThermo[8] = {
0x28, 0x7A, 0x8B, 0xC0, 0x03, 0x00, 0x00, 0x2F};
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char cosmKey[] = "l6ab.....................................0Zz0g";
int sensorPin = 3;
int second, minute, hour, weekDay, monthDay, month, year;
float InTemp, OutTemp;
// Define the strings for our datastream IDs
char sensorId0[] = "InThermo";
char sensorId1[] = "OutThermo";
//char sensorId2{} = "DrainThermo"
const int bufferSize = 100;
char bufferValue[bufferSize]; // enough space to store the string we're going to send
CosmDatastream datastreams[] = {
CosmDatastream(sensorId0, strlen(sensorId0), DATASTREAM_FLOAT),
CosmDatastream(sensorId1, strlen(sensorId1), DATASTREAM_FLOAT),
// CosmDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
CosmFeed feed(83153, datastreams, 2 /*put your number here */);
EthernetClient client;
CosmClient cosmclient(client);
LiquidCrystal lcd(8,9,16,5,6,7);
void setup() {
Wire.begin();
Serial.begin(9600);
delay(300);//Wait for newly restarted system to stabilize
Serial.print("Temperature measurement");
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
sensors.setResolution(InThermo, 12);
sensors.setResolution(OutThermo, 12);
Serial.println("Starting multiple datastream upload to Cosm...");
Serial.println();
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(10000);
}
}
void loop() {
GetClock();
PrintDate;
sensors.requestTemperatures();
Serial.println("Read sensor value ");
InTemp = (sensorValue(InThermo));
OutTemp = (sensorValue(OutThermo));
// float Drain = (sensorValue(DrainThermo));
datastreams[0].setFloat(InTemp);
datastreams[1].setFloat(OutTemp);
Serial.println(datastreams[0]);
Serial.println(datastreams[1]);
/*
datastreams[2].setFloat(DrainTemp);
Serial.println(datastreams[2].getFloat(DrainTemp));
*/
// LCD stuff will go here
if (second == 0 || second == 10 || second == 20 || second == 30 || second == 40 || second == 50)
{
myFile = SD.open("data.csv", FILE_WRITE);//<<<<<<<<<<<<< OPEN
WriteSD;
int ret=0;
delay(200);// Delay... must not be too short.
Serial.println("Uploading it to Cosm");
ret = cosmclient.put(feed, cosmKey); // SEND FEED TO COSM
Serial.print("cosmclient.put returned "); // tell us about it
Serial.println(ret); // pray to God it says 200
myFile.println();
myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
}
delay(200);// Delay... must not be too short.
Serial.println();
delay(800);
}
//sensorValue function
float sensorValue (byte deviceAddress[])
{
float tempC = sensors.getTempC (deviceAddress);
return tempC;
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void GetClock(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
void PrintDate () {
Serial.print(monthDay);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
if (second < 10)
{
Serial.print("0");
};
Serial.print(second);
Serial.print(" ");
}
void WriteSD () {
myFile.print(monthDay);
myFile.print("/");
myFile.print(month);
myFile.print("/");
myFile.print(year);
myFile.print(", ");
myFile.print(hour);
myFile.print(":");
myFile.print(minute);
myFile.print(":");
myFile.print(second);
myFile.print(", ");
myFile.print(InTemp);
myFile.print(", ");
myFile.print(OutTemp);
myFile.print(", ");
}