Skip to content

Commit

Permalink
change publishing payload for electric-io; closes #45
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Satrom committed Mar 22, 2019
1 parent 4745b6a commit 2cccc9a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
20 changes: 19 additions & 1 deletion brew-buddy-firmware/src/brew-buddy-firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void clearScreen();
void printHeadingTextLine(String text);
void printSubheadingLine(String text);
float readTemp();
void postSensorData();
void postTemp(float temp);
void postFermentationRate();
void printReading(float reading);
Expand Down Expand Up @@ -192,7 +193,7 @@ void setup()

//Connect to Azure MQTT Server
client.enableTls(certificates, sizeof(certificates));
client.connect(deviceID, "brew-buddy-hub.azure-devices.net/" + deviceID, "SharedAccessSignature sr=brew-buddy-hub.azure-devices.net&sig=kNKhEIQaObc74GPvEoK4fi3W1ot65f5aQDOFnTdkaqY%3D&skn=iothubowner&se=1553119278");
client.connect(deviceID, "brew-buddy-hub.azure-devices.net/" + deviceID, "SharedAccessSignature sr=brew-buddy-hub.azure-devices.net&sig=PQZleYaaxEu5VDlE9NTjKWpN%2FnZdL2MBu%2B0A5Xl2YbM%3D&skn=iothubowner&se=1553642020");
if (client.isConnected())
{
Particle.publish("mqtt/status", "connected");
Expand Down Expand Up @@ -310,6 +311,8 @@ void loop()
{
postFermentationRate();
}

postSensorData();
}

if (client.isConnected())
Expand Down Expand Up @@ -519,6 +522,21 @@ float readTemp()
}
}

void postSensorData()
{
JsonWriterStatic<256> jsonWriter;

{
JsonWriterAutoObject obj(&jsonWriter);

jsonWriter.insertKeyValue("temperature", lastTemp);
jsonWriter.insertKeyValue("fermentation-rate", fermentationRate);
jsonWriter.insertKeyValue("battery-charge", String(getBattPercentage()));
}

Particle.publish(messageBase + "latest", jsonWriter.getBuffer());
}

void postTemp(float temp)
{
Particle.publish(messageBase + "brew/temp", String(temp, 2));
Expand Down
19 changes: 18 additions & 1 deletion brew-buddy-firmware/src/brew-buddy-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void setup()

//Connect to Azure MQTT Server
client.enableTls(certificates, sizeof(certificates));
client.connect(deviceID, "brew-buddy-hub.azure-devices.net/" + deviceID, "SharedAccessSignature sr=brew-buddy-hub.azure-devices.net&sig=kNKhEIQaObc74GPvEoK4fi3W1ot65f5aQDOFnTdkaqY%3D&skn=iothubowner&se=1553119278");
client.connect(deviceID, "brew-buddy-hub.azure-devices.net/" + deviceID, "SharedAccessSignature sr=brew-buddy-hub.azure-devices.net&sig=PQZleYaaxEu5VDlE9NTjKWpN%2FnZdL2MBu%2B0A5Xl2YbM%3D&skn=iothubowner&se=1553642020");
if (client.isConnected())
{
Particle.publish("mqtt/status", "connected");
Expand Down Expand Up @@ -276,6 +276,8 @@ void loop()
{
postFermentationRate();
}

postSensorData();
}

if (client.isConnected())
Expand Down Expand Up @@ -485,6 +487,21 @@ float readTemp()
}
}

void postSensorData()
{
JsonWriterStatic<256> jsonWriter;

{
JsonWriterAutoObject obj(&jsonWriter);

jsonWriter.insertKeyValue("temperature", lastTemp);
jsonWriter.insertKeyValue("fermentation-rate", fermentationRate);
jsonWriter.insertKeyValue("battery-charge", String(getBattPercentage()));
}

Particle.publish(messageBase + "latest", jsonWriter.getBuffer());
}

void postTemp(float temp)
{
Particle.publish(messageBase + "brew/temp", String(temp, 2));
Expand Down

0 comments on commit 2cccc9a

Please sign in to comment.