Created
May 29, 2015 15:02
-
-
Save evfairchild/2399bc88a2df690531b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <OneWire.h> | |
#include <Console.h> | |
#include <DallasTemperature.h> | |
#include "lights.h" | |
#define BUF_SIZE 256 | |
#define REPORT_INTERVAL 30000 // ROBERTO, This was 3000 ms instead of 30000. | |
/*-----( Declare Constants and Pin Numbers )-----*/ | |
#define TEMPERATURE_PRECISION 9 | |
#define NUM_TEMPERATURE_SENSORS 4 | |
int sensor_pin = 2; | |
/*-----( Declare objects )-----*/ | |
OneWire onewire_bus(sensor_pin); | |
DallasTemperature sensor_bus(&onewire_bus); | |
DeviceAddress Therms[NUM_TEMPERATURE_SENSORS]; | |
int count = 1; | |
float temperatures[NUM_TEMPERATURE_SENSORS] = {0.0}; | |
float lastTemperatures[NUM_TEMPERATURE_SENSORS] = {0.0}; | |
unsigned long lastTemperatureReports[NUM_TEMPERATURE_SENSORS] = {0}; | |
unsigned long now = 0; | |
char buf[BUF_SIZE]; | |
int led = 13; | |
bool sendData(int sensor_pin, float value, char* deviceId, unsigned long* lastReport, float* lastValue); | |
void printAddress(DeviceAddress deviceAddress) | |
{ | |
for (uint8_t i = 0; i < 8; i++) | |
{ | |
// zero pad the address if necessary | |
if (deviceAddress[i] < 16) Console.print("0"); | |
Console.print(deviceAddress[i], HEX); | |
} | |
} | |
void setup() /****** SETUP: RUNS ONCE ******/ | |
{ | |
Bridge.begin(); | |
Console.begin(); | |
for (int i=0; i<NUM_TEMPERATURE_SENSORS; i++){ | |
sensor_bus.getAddress(Therms[i], i); | |
sensor_bus.setResolution(Therms[i], TEMPERATURE_PRECISION); | |
} | |
delay(50); | |
} | |
void loop(void) | |
{ | |
if(!Console.connected()) { | |
return; | |
} | |
int sensor_index = 0; | |
// call sensors.requestTemperatures() to issue a global temperature | |
for (int i=0; i<NUM_TEMPERATURE_SENSORS; i++){ | |
sensor_bus.requestTemperatures(); | |
temperatures[i] = sensor_bus.getTempC(Therms[i]); | |
sendData(sensor_pin, temperatures[i], Therms[i], &lastTemperatureReports[i], &lastTemperatures[i]); | |
} | |
delay(50); | |
} | |
bool sendData(int pin, float value, DeviceAddress deviceId, unsigned long* lastReport, float* lastValue) | |
{ | |
unsigned long now = millis(); | |
if(now - *lastReport >= REPORT_INTERVAL) { | |
Console.print("key=refrigeration.pin"); | |
Console.print(", Pin="); | |
Console.print(pin); | |
Console.print(", DeviceID="); | |
printAddress(deviceId); | |
Console.print(", value="); | |
Console.print(value); | |
Console.println(); | |
*lastValue = value; | |
*lastReport = now; | |
blink(led); | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment