Skip to content

Commit

Permalink
More ThingSpeak backend support
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Nov 28, 2020
1 parent a11a809 commit 4f2e58e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 78 deletions.
32 changes: 15 additions & 17 deletions data/settings.htm
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<a class="dropdown-item" data-toggle="tab" href="#urltarget">URL Target</a>
<a class="dropdown-item" data-toggle="tab" href="#brewersfriend">Brewer's Friend</a>
<a class="dropdown-item" data-toggle="tab" href="#brewfather">Brewfather</a>
<a class="dropdown-item" data-toggle="tab" href="#thingspeak">Thingspeak</a>
<a class="dropdown-item" data-toggle="tab" href="#thingspeak">ThingSpeak</a>
</div>
</li> <!-- Targets Nav Item -->

Expand Down Expand Up @@ -471,29 +471,27 @@ <h4 class="card-title">ThingSpeak Target Settings</h4>
<li class="list-group-item">

<p class="card-text">
These settings control how Brew Bubbles talks to
<a href="https://thingspeak.com/">ThingSpeak.</a>
ThingSpeak supports logging brew-related data, and
with some imagination, several dashboards may be
created to visualize and make use of your data. To
find your API key; log into your ThingSpeak account
and go to `My Profile.' Your API key will be a 10
to 64-character string of letters and numbers in the
'ThingSpeak Settings' section.
These settings control how Brew Bubbles talks to <a href="https://thingspeak.com/">ThingSpeak.</a>
ThingSpeak supports logging brew-related data, and with some imagination, several dashboards may be
created to visualize and make use of your data.
</p>
<p class="card-text">
To find your channel's ID and write key key; log into your ThingSpeak account and go to 'My Channels.'
Select the 'API Keys' tab for your channel. The channel ID and write API key will be displayed.
</p>

<form id="setthingspeakchannel" action="/settings/update/" method="POST">
<!-- ThingSpeak Channel Form -->
<div class="form-group row">
<label for="thingSpeakChannel" class="col-sm-2 col-form-label"
data-toggle="tooltip"
title="Enter the Channel number of your target ThingSpeak channel.">
ThingSpeak Channel
title="Enter the Channel ID of your target ThingSpeak channel.">
Channel ID
</label>
<div class="col-sm-8">
<input type="number" class="form-control" id="thingspeakchannel"
name="thingspeakchannel" min="1000" max="9999999999"
placeholder="1234567890">
placeholder="1234567">
</div>
<div class="col-sm-2"><button class="btn btn-primary"
id="submitSettings">Update</button>
Expand All @@ -506,13 +504,13 @@ <h4 class="card-title">ThingSpeak Target Settings</h4>
<div class="form-group row">
<label for="thingSpeakKey" class="col-sm-2 col-form-label"
data-toggle="tooltip"
title="Enter the Write API Key from your ThingSpeak channel. To disable pushing to ThingSpeak, delete the key.">
ThingSpeak Key
title="Enter the Write API key from your ThingSpeak channel. To disable pushing to ThingSpeak, delete the key.">
Channel Write Key
</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="thingspeakkey"
name="thingspeakkey" minlength="10" maxlength="64"
placeholder="DD24FNDN84305AJ">
placeholder="A0123456789ABCDE">
</div>
<div class="col-sm-2"><button class="btn btn-primary"
id="submitSettings">Update</button>
Expand All @@ -529,7 +527,7 @@ <h4 class="card-title">ThingSpeak Target Settings</h4>
Frequency</label>
<div class="col-sm-8">
<input type="number" class="form-control" id="thingspeakfreq"
placeholder="15" name="thingspeakfreq" min="15" max="120">
placeholder="15" name="thingspeakfreq" min="1" max="120">
</div>
<div class="col-sm-2"><button class="btn btn-primary"
id="submitSettings">Update</button>
Expand Down
121 changes: 60 additions & 61 deletions src/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,67 +464,66 @@ void setSettingsAliases()
strcat(redirect, hashloc); // Redirect to Brewfather Control
Log.notice(F("POSTed brewfatherfreq, redirecting to %s." CR), redirect);
}
// TODO:
// else if (strcmp(name, "thingspeakchannel") == 0) // Change Thingspeeak frequency
// {
// const char *hashloc = "#thingspeak";
// if (strlen(value) == 0)
// {
// Log.notice(F("Settings update, [%s]:(%s) applied. Disabling ThingSpeak Target." CR), name, value);
// config.thingspeak.channel = 0;
// }
// else if ((atoi(value) < 1000) || (atoi(value) > 9999999999))
// {
// Log.warning(F("Settings update error, [%s]:(%s) not applied." CR), name, value);
// }
// else
// {
// Log.notice(F("Settings update, [%s]:(%s) applied." CR), name, value);
// config.thingspeak.channel = atoi(value);
// config.thingspeak.update = true;
// saveConfig();
// }
// strcat(redirect, hashloc); // Redirect to ThingSpeak Control
// Log.notice(F("POSTed thingspeakchannel, redirecting to %s." CR), redirect);
// }
// else if (strcmp(name, "thingspeakkey") == 0) // Change ThingSpeak key
// {
// const char *hashloc = "#thingspeak";
// if (strlen(value) == 0)
// {
// Log.notice(F("Settings update, [%s]:(%s) applied. Disabling ThingSpeak Target." CR), name, value);
// strlcpy(config.thingspeak.key, value, sizeof(config.thingspeak.key));
// }
// else if ((strlen(value) < 10) || (strlen(value) > 64))
// {
// Log.warning(F("Settings update error, [%s]:(%s) not applied." CR), name, value);
// }
// else
// {
// Log.notice(F("Settings update, [%s]:(%s) applied." CR), name, value);
// strlcpy(config.thingspeak.key, value, sizeof(config.thingspeak.key));
// saveConfig();
// }
// strcat(redirect, hashloc); // Redirect to ThingSpeak Control
// Log.notice(F("POSTed thingspeeakkey, redirecting to %s." CR), redirect);
// }
// else if (strcmp(name, "thingspeakfreq") == 0) // Change Thingspeeak frequency
// {
// const char *hashloc = "#thingspeak";
// if ((atoi(value) < 15) || (atoi(value) > 120))
// {
// Log.warning(F("Settings update error, [%s]:(%s) not applied." CR), name, value);
// }
// else
// {
// Log.notice(F("Settings update, [%s]:(%s) applied." CR), name, value);
// config.thingspeak.freq = atoi(value);
// config.thingspeak.update = true;
// saveConfig();
// }
// strcat(redirect, hashloc); // Redirect to ThingSpeak Control
// Log.notice(F("POSTed thingspeakfreq, redirecting to %s." CR), redirect);
// }
else if (strcmp(name, "thingspeakchannel") == 0) // Change Thingspeeak frequency
{
const char *hashloc = "#thingspeak";
if (strlen(value) == 0)
{
Log.notice(F("Settings update, [%s]:(%s) applied. Disabling ThingSpeak Target." CR), name, value);
config.thingspeak.channel = 0;
}
else if ((atoi(value) < 1000) || (atoi(value) > 9999999999))
{
Log.warning(F("Settings update error, [%s]:(%s) not applied." CR), name, value);
}
else
{
Log.notice(F("Settings update, [%s]:(%s) applied." CR), name, value);
config.thingspeak.channel = atoi(value);
config.thingspeak.update = true;
saveConfig();
}
strcat(redirect, hashloc); // Redirect to ThingSpeak Control
Log.notice(F("POSTed thingspeakchannel, redirecting to %s." CR), redirect);
}
else if (strcmp(name, "thingspeakkey") == 0) // Change ThingSpeak key
{
const char *hashloc = "#thingspeak";
if (strlen(value) == 0)
{
Log.notice(F("Settings update, [%s]:(%s) applied. Disabling ThingSpeak Target." CR), name, value);
strlcpy(config.thingspeak.key, value, sizeof(config.thingspeak.key));
}
else if ((strlen(value) < 10) || (strlen(value) > 64))
{
Log.warning(F("Settings update error, [%s]:(%s) not applied." CR), name, value);
}
else
{
Log.notice(F("Settings update, [%s]:(%s) applied." CR), name, value);
strlcpy(config.thingspeak.key, value, sizeof(config.thingspeak.key));
saveConfig();
}
strcat(redirect, hashloc); // Redirect to ThingSpeak Control
Log.notice(F("POSTed thingspeeakkey, redirecting to %s." CR), redirect);
}
else if (strcmp(name, "thingspeakfreq") == 0) // Change Thingspeeak frequency
{
const char *hashloc = "#thingspeak";
if ((atoi(value) < 1) || (atoi(value) > 120))
{
Log.warning(F("Settings update error, [%s]:(%s) not applied." CR), name, value);
}
else
{
Log.notice(F("Settings update, [%s]:(%s) applied." CR), name, value);
config.thingspeak.freq = atoi(value);
config.thingspeak.update = true;
saveConfig();
}
strcat(redirect, hashloc); // Redirect to ThingSpeak Control
Log.notice(F("POSTed thingspeakfreq, redirecting to %s." CR), redirect);
}
else // Settings pair not found
{
Log.warning(F("Settings update error, [%s]:(%s) not applied." CR), name, value);
Expand Down

0 comments on commit 4f2e58e

Please sign in to comment.