jamestech:
Thanks,
VPS = Virtual Private Server, in short it simply means we have our own web server to process the data and we would like to keep it this way, it gives us full control of the data and minimal dependencies on a third party.
We intend to have a few of these Arduino's spread around various locations where the internet connection would be made available to us, but we would have no control over it. For this reason sending the data out as a web client to our own web server makes sense. The data will be submitted with timestamps and will be used to create human read historical reports, so as long as the Arduino timestamps the data on collection I'd be happy submitting the data as infrequently as every hour.
Something I have noticed is that my timestamps in the previously posted code seem to be all over the place, do you know why this might be?
I have two outposts, one under a ski lodge and one in a residence, both several hours drive away, and in opposite directions. The former is inaccessible for the season - about ninety days. The latter can be be visited any time but usually annually. No local attention is expected at either, but they have local display and local bluetooth transmission. Ordinary domestic internet connection is available at both and that is all that is needed.
Timestamped data is downloadable from Xively but I have only done that once. Few things promote a reality check quite like a plethora of data, and a PrintScreen of a Xively page generally suffices. Everything is available from the SD but I don't read it remotely.
IF you are accumulating data in a regular manner, AND your receiver allows you to send at the same frequency, I see no point in sending it on in batches. If you are having a problem, you are probably just moving it rather than fixing it, and are likely to incur new problems in the process. IF NOT to both the above, Xively and those of that ilk are probably not the best way to go.
I'm afraid the code is meaningless, but it seems unnecessarily complicated. This could be partly because it is event-dependent rather than under the control of the Arduino.
The organisation of the code below might be useful. Strip out what you need.
/*
3x DS18B20 sensors at one second intervals. Nokia 5110 LCD
Two of the temperatures, plus the difference between them, is transmitted
over bluetooth in a format suitable for BlueTooth Terminal/Graphics (CETIN)
in order to display three graphs in real time. 2014 VERSION
Every tenth reading is recorded on SD card in real numbers to two decimal
places. Each line is timestamped.
A new file is created at midnight using the date as the filename.
Credit to Hacktronics, Mellis & Igoe, Garage Box, Bildr.org, etc.
Kudos to lar3ry in Saskatchewan, Stanley in KL, Coding Badly in Tx.
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <PCD8544.h> // Nokia 5110
#include "Wire.h" // MUST HAVE lib for LCD disp, SD card
#include <SD.h>
#include <SPI.h> // SD
#include "RTClib.h" //Date As Filename
#include <string.h> //Date As Filename
#define DS1307_ADDRESS 0x68
RTC_DS1307 RTC;
char filename[] = "00000000.CSV";
File myFile;
static PCD8544 lcd;
// Custom symbols
static const byte DEGREES_CHAR = 1;
static const byte degrees_glyph[] = { 0x00, 0x07, 0x05, 0x07, 0x00 };
static const byte SLASH_CHAR = 2;
static const byte slash_glyph[] = {0x00,0x20,0x10,0x08};
// Yellow group BEN BULLEN (red LED)
byte InThermo[8] = {
0x28, 0x39, 0xFD, 0x50, 0x04, 0x00, 0x00, 0X69};
byte OutThermo[8] = {
0x28, 0x09, 0xA9, 0xC0, 0x03, 0x00, 0x00, 0x95};
byte DrainThermo[8] = {
0x28, 0x62, 0xA5, 0x2D, 0x04, 0x00, 0x00, 0x21};
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int second, minute, hour, weekDay, monthDay, month, year;
int k=0;
const int chipSelect = 4;
float InTemp, OutTemp, DrainTemp, diff;
// Define the strings for our datastream IDs
char sensorId0[] = "InThermo";
char sensorId1[] = "OutThermo";
char sensorId2[] = "DrainThermo";
char strIn[8];
char strOut[8];
char strDrain[8];
char strdiff[8];
String stringOne, stringTwo, stringThree, stringFour;
void setup() {
lcd.begin(84, 48);
// Register the custom symbols...
lcd.createChar(DEGREES_CHAR, degrees_glyph);
lcd.createChar(SLASH_CHAR, slash_glyph);
Wire.begin();
Serial.begin(9600);
//RTC.begin();
delay(300);//Wait for newly restarted system to stabilize
lcd.setCursor (0,0);
lcd.println("Init SD CARD");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
//pinMode(10, OUTPUT);// Uno
pinMode(53, OUTPUT);//MEGA
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect))
{
lcd.println("Card failed");
// don't do anything more:
return;
}
lcd.println("CARD OK");
delay(2000);
getFileName();
lcd.setCursor(0,3);
lcd.println(filename);
delay(2000);
lcd.clear();
sensors.setResolution(InThermo, 12);
sensors.setResolution(OutThermo, 12);
sensors.setResolution(DrainThermo, 12);
//Sequence for bluetooth
// "E256,-321,982\n"
//so insert three variable between four strings, two are the same twice,
//to make a fourth string
stringOne = String("E");
stringTwo = String(",");
stringThree = String("\n");
running();
}
void loop() {
GetClock();
if (hour == 0 && minute == 0 && second <2)
{
getFileName();
}
//get the values from the DS8B20's
sensors.requestTemperatures();
InTemp = (sensorValue(InThermo));
OutTemp = (sensorValue(OutThermo));
DrainTemp = (sensorValue(DrainThermo));
diff = OutTemp - InTemp;
dtostrf(InTemp,4, 2, strIn);
dtostrf(OutTemp,4, 2, strOut);
dtostrf(diff,4, 2, strdiff);
stringFour = stringOne + strIn + stringTwo + strOut;
stringFour = stringFour + stringTwo + strdiff + stringThree;
Serial.println(stringFour);
lcd.setCursor(49,0);
lcd.print(InTemp);
lcd.setCursor(49,1);
lcd.print (OutTemp);
lcd.setCursor(49,2);
lcd.print(DrainTemp);
lcd.setCursor(49,3);
lcd.print(diff);
lcd.print(" ");
lcd.setCursor(17,5);
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
lcd.print(" ");
k=k+1;
if (k>9 )
{
myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
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(",");
myFile.print(DrainTemp);
myFile.print(",");
myFile.print(diff);
myFile.println();
myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
k=0;
}
delay(850);
} // loop ends here
//sensorValue function
float sensorValue (byte deviceAddress[])
{
float tempC = sensors.getTempC (deviceAddress);
return tempC;
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal bers
return ( (val/16*10) + (val%16) );
}
void running(){
lcd.setCursor(0,0);
lcd.print("In");
lcd.setCursor(31,0);
lcd.print("\001C ");
lcd.setCursor(0,1);
lcd.print("Out");
lcd.setCursor(31,1);
lcd.print("\001C ");
lcd.setCursor(0,2);
lcd.print("Drain");
lcd.setCursor(31,2);
lcd.print("\001C ");
lcd.setCursor(0,3);
lcd.print("diff");
lcd.setCursor(31,3);
lcd.print("\001C ");
lcd.setCursor(15,4);
lcd.print("Bluetooth");
}
void getFileName(){
DateTime now = RTC.now();
sprintf(filename, "%02d%02d%02d.csv", now.year(), now.month(), now.day());
}
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());
}