Skip to content

Commit 42cb7f9

Browse files
author
Brandon Satrom
authored
Merge pull request #28 from bsatrom/feature/cloud-readings
Feature/cloud readings
2 parents c83e757 + d9ca6c4 commit 42cb7f9

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

brew-buddy-firmware/src/brew-buddy-firmware.cpp

+30-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void printHeadingTextLine(String text);
2727
void printSubheadingLine(String text);
2828
float readTemp();
2929
void postTemp(float temp);
30+
void postFermentationRate();
3031
void printReading(float reading);
3132
void displayStageName(String stagename);
3233
void displayFermentationHeading();
@@ -80,6 +81,10 @@ unsigned long startTime = 0;
8081
unsigned long elapsedTime;
8182
float previousTemp = 0;
8283

84+
// Timing variables for posting readings to the cloud
85+
unsigned long postInterval = 120000;
86+
unsigned long previousPostMillis = 0;
87+
8388
//Text Size Variables
8489
const uint8_t headingTextSize = 4;
8590
const uint8_t subheadTextSize = 2;
@@ -92,6 +97,7 @@ const uint8_t pixelMultiplier = 7; //Used to clear text portions of the screen
9297
QueueArray<int> tempGraphArray;
9398
const uint8_t lowTemp = 70;
9499
const uint8_t highTemp = 220;
100+
float lastTemp = 0.0;
95101

96102
//Brew Stage Variables
97103
bool isBrewingMode = false;
@@ -104,7 +110,7 @@ unsigned long fermentationStartTime = 0;
104110

105111
// Variables for fermentation rate
106112
QueueArray<long> knockArray;
107-
long fermentationRate = 0; // knocks per ms
113+
float fermentationRate = 0; // knocks per ms
108114
unsigned long lastKnock;
109115

110116
String brewStage;
@@ -218,6 +224,20 @@ void loop()
218224

219225
displayTime(elapsedTime);
220226
}
227+
228+
if (currentMillis - previousPostMillis > postInterval)
229+
{
230+
previousPostMillis = millis();
231+
232+
if (isBrewingMode)
233+
{
234+
postTemp(lastTemp);
235+
}
236+
else if (isFermentationMode)
237+
{
238+
postFermentationRate();
239+
}
240+
}
221241
}
222242
}
223243

@@ -365,7 +385,7 @@ float readTemp()
365385

366386
if (!isnan(temperature))
367387
{
368-
postTemp(temperature);
388+
lastTemp = temperature;
369389

370390
return temperature;
371391
}
@@ -378,8 +398,14 @@ float readTemp()
378398

379399
void postTemp(float temp)
380400
{
381-
String payload = "{ \"a\":" + String(temp, 2) + ", \"b\": \"" + brewId + "\", \"c\": \"" + brewStage + "\" }";
382-
Particle.publish("BrewStageTemp", payload);
401+
String payload = "{ \"temperature\":" + String(temp, 2) + ", \"time\": \"" + millis() + "\" }";
402+
Particle.publish("brewing/temp", payload);
403+
}
404+
405+
void postFermentationRate()
406+
{
407+
String payload = "{ \"current_rate\":" + String(fermentationRate, 2) + ", \"time\": \"" + millis() + "\" }";
408+
Particle.publish("fermentation/rate", payload);
383409
}
384410

385411
void printReading(float reading)

brew-buddy-firmware/src/brew-buddy-firmware.ino

+29-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ unsigned long startTime = 0;
5555
unsigned long elapsedTime;
5656
float previousTemp = 0;
5757

58+
// Timing variables for posting readings to the cloud
59+
unsigned long postInterval = 120000;
60+
unsigned long previousPostMillis = 0;
61+
5862
//Text Size Variables
5963
const uint8_t headingTextSize = 4;
6064
const uint8_t subheadTextSize = 2;
@@ -67,6 +71,7 @@ const uint8_t pixelMultiplier = 7; //Used to clear text portions of the screen
6771
QueueArray<int> tempGraphArray;
6872
const uint8_t lowTemp = 70;
6973
const uint8_t highTemp = 220;
74+
float lastTemp = 0.0;
7075

7176
//Brew Stage Variables
7277
bool isBrewingMode = false;
@@ -79,7 +84,7 @@ unsigned long fermentationStartTime = 0;
7984

8085
// Variables for fermentation rate
8186
QueueArray<long> knockArray;
82-
long fermentationRate = 0; // knocks per ms
87+
float fermentationRate = 0; // knocks per ms
8388
unsigned long lastKnock;
8489

8590
String brewStage;
@@ -193,6 +198,20 @@ void loop()
193198

194199
displayTime(elapsedTime);
195200
}
201+
202+
if (currentMillis - previousPostMillis > postInterval)
203+
{
204+
previousPostMillis = millis();
205+
206+
if (isBrewingMode)
207+
{
208+
postTemp(lastTemp);
209+
}
210+
else if (isFermentationMode)
211+
{
212+
postFermentationRate();
213+
}
214+
}
196215
}
197216
}
198217

@@ -340,7 +359,7 @@ float readTemp()
340359

341360
if (!isnan(temperature))
342361
{
343-
postTemp(temperature);
362+
lastTemp = temperature;
344363

345364
return temperature;
346365
}
@@ -353,8 +372,14 @@ float readTemp()
353372

354373
void postTemp(float temp)
355374
{
356-
String payload = "{ \"a\":" + String(temp, 2) + ", \"b\": \"" + brewId + "\", \"c\": \"" + brewStage + "\" }";
357-
Particle.publish("BrewStageTemp", payload);
375+
String payload = "{ \"temperature\":" + String(temp, 2) + ", \"time\": \"" + millis() + "\" }";
376+
Particle.publish("brewing/temp", payload);
377+
}
378+
379+
void postFermentationRate()
380+
{
381+
String payload = "{ \"current_rate\":" + String(fermentationRate, 2) + ", \"time\": \"" + millis() + "\" }";
382+
Particle.publish("fermentation/rate", payload);
358383
}
359384

360385
void printReading(float reading)

0 commit comments

Comments
 (0)