Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Emoncms Path setting for issue34 #38

Merged
merged 2 commits into from Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified docs/emoncms.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions readme.md
Expand Up @@ -104,10 +104,11 @@ On future boots EmonESP will automatically connect to this network.

EmonESP can post data to [emoncms.org](https://emoncms.org) or any other Emoncms server (e.g. emonPi) using [Emoncms API](https://emoncms.org/site/api#input).

Data ca be posted using HTTP or HTTPS. For HTTPS the Emoncms server must support HTTPS (emoncms.org does, emonPi does not). Due to the limited resources on the ESP the SSL SHA-1 fingerprint for the Emoncms server certificate must be manually entered and regularly updated.
In the *Emoncms Server* field, enter just the hostname or address without any path (e.g. emoncms.org), in the *Emoncms Path* field enter the path including the leading slash (e.g. /emoncms) or leave it empty if not required.

Data can be posted using HTTP or HTTPS. For HTTPS the Emoncms server must support HTTPS (emoncms.org does, emonPi does not). Due to the limited resources on the ESP the SSL SHA-1 fingerprint for the Emoncms server certificate must be manually entered and regularly updated.

*Note: the emoncms.org fingerprint will change every 90 days when the SSL certificate is renewed.*
*Note 2: currently, when using a custon server with HTTPS, the Emoncms Server field must be just the hostname without any additional path, see issue #34.*

To obtain the certificate fingerprint, you can use several methods, some examples:
* Chrome under Windows: click the secure icon next to the address bar and click on the certificate row to get the details, in the *Details* tab copy the hexadecimal digits from the box *Thumbprint* substituting spaces with colons and paying attention not to include any leading invisible character;
Expand Down
12 changes: 11 additions & 1 deletion src/config.cpp
Expand Up @@ -39,6 +39,7 @@ String www_password = "";

// EMONCMS SERVER strings
String emoncms_server = "";
String emoncms_path = "";
String emoncms_node = "";
String emoncms_apikey = "";
String emoncms_fingerprint = "";
Expand All @@ -54,6 +55,7 @@ String mqtt_feed_prefix = "";
#define EEPROM_EPASS_SIZE 64
#define EEPROM_EMON_API_KEY_SIZE 32
#define EEPROM_EMON_SERVER_SIZE 45
#define EEPROM_EMON_PATH_SIZE 16
#define EEPROM_EMON_NODE_SIZE 32
#define EEPROM_MQTT_SERVER_SIZE 45
#define EEPROM_MQTT_TOPIC_SIZE 32
Expand Down Expand Up @@ -91,6 +93,8 @@ String mqtt_feed_prefix = "";
#define EEPROM_WWW_USER_END (EEPROM_WWW_USER_START + EEPROM_WWW_USER_SIZE)
#define EEPROM_WWW_PASS_START EEPROM_WWW_USER_END
#define EEPROM_WWW_PASS_END (EEPROM_WWW_PASS_START + EEPROM_WWW_PASS_SIZE)
#define EEPROM_EMON_PATH_START EEPROM_WWW_PASS_END
#define EEPROM_EMON_PATH_END (EEPROM_EMON_PATH_START + EEPROM_EMON_PATH_SIZE)

// -------------------------------------------------------------------
// Reset EEPROM, wipes all settings
Expand Down Expand Up @@ -138,6 +142,8 @@ void config_load_settings()
emoncms_apikey);
EEPROM_read_string(EEPROM_EMON_SERVER_START, EEPROM_EMON_SERVER_SIZE,
emoncms_server);
EEPROM_read_string(EEPROM_EMON_PATH_START, EEPROM_EMON_PATH_SIZE,
emoncms_path);
EEPROM_read_string(EEPROM_EMON_NODE_START, EEPROM_EMON_NODE_SIZE,
emoncms_node);
EEPROM_read_string(EEPROM_EMON_FINGERPRINT_START,
Expand All @@ -155,9 +161,10 @@ void config_load_settings()
EEPROM_read_string(EEPROM_WWW_PASS_START, EEPROM_WWW_PASS_SIZE, www_password);
}

void config_save_emoncms(String server, String node, String apikey, String fingerprint)
void config_save_emoncms(String server, String path, String node, String apikey, String fingerprint)
{
emoncms_server = server;
emoncms_path = path;
emoncms_node = node;
emoncms_apikey = apikey;
emoncms_fingerprint = fingerprint;
Expand All @@ -168,6 +175,9 @@ void config_save_emoncms(String server, String node, String apikey, String finge
// save emoncms server to EEPROM max 45 characters
EEPROM_write_string(EEPROM_EMON_SERVER_START, EEPROM_EMON_SERVER_SIZE, emoncms_server);

// save emoncms server to EEPROM max 16 characters
EEPROM_write_string(EEPROM_EMON_PATH_START, EEPROM_EMON_PATH_SIZE, emoncms_path);

// save emoncms node to EEPROM max 32 characters
EEPROM_write_string(EEPROM_EMON_NODE_START, EEPROM_EMON_NODE_SIZE, emoncms_node);

Expand Down
3 changes: 2 additions & 1 deletion src/config.h
Expand Up @@ -46,6 +46,7 @@ extern String www_password;

// EMONCMS SERVER strings
extern String emoncms_server;
extern String emoncms_path;
extern String emoncms_node;
extern String emoncms_apikey;
extern String emoncms_fingerprint;
Expand All @@ -65,7 +66,7 @@ extern void config_load_settings();
// -------------------------------------------------------------------
// Save the EmonCMS server details
// -------------------------------------------------------------------
extern void config_save_emoncms(String server, String node, String apikey, String fingerprint);
extern void config_save_emoncms(String server, String path, String node, String apikey, String fingerprint);

// -------------------------------------------------------------------
// Save the MQTT broker details
Expand Down
4 changes: 3 additions & 1 deletion src/data/config.js
Expand Up @@ -89,7 +89,8 @@ function ConfigViewModel() {
BaseViewModel.call(this, {
"ssid": "",
"pass": "",
"emoncms_server": "data.openevse.com/emoncms",
"emoncms_server": "data.openevse.com",
"emoncms_path": "/emoncms",
"emoncms_apikey": "",
"emoncms_node": "",
"emoncms_fingerprint": "",
Expand Down Expand Up @@ -246,6 +247,7 @@ function EmonEspViewModel() {
self.saveEmonCms = function () {
var emoncms = {
server: self.config.emoncms_server(),
path: self.config.emoncms_path(),
apikey: self.config.emoncms_apikey(),
node: self.config.emoncms_node(),
fingerprint: self.config.emoncms_fingerprint()
Expand Down
21 changes: 15 additions & 6 deletions src/data/home.html
Expand Up @@ -83,12 +83,21 @@ <h2>1. WiFi Network</h2>
<div id="two">
<h2>2. Emoncms</h2>
<div class="itembody-wrapper">
<b>Emoncms Server*:</b><br>
<input type="text" data-bind="textInput: config.emoncms_server"><br/>
<span>
e.g '<a href="https://emoncms.org">emoncms.org</a>',
'emonpi/emoncms', or '192.168.1.4/emoncms'
</span><br/>
<p>
<b>Emoncms Server*:</b><br>
<input type="text" data-bind="textInput: config.emoncms_server"><br/>
<span>
e.g '<a href="https://emoncms.org">emoncms.org</a>',
'emonpi', or '192.168.1.4'
</span><br/>
</p>
<p>
<b>Emoncms Path:</b><br>
<input type="text" data-bind="textInput: config.emoncms_path"><br/>
<span>
e.g '/emoncms', or empty for emoncms.org
</span><br/>
</p>
<p>
<b>Emoncms Node Name*:</b><br>
<input type="text" data-bind="textInput: config.emoncms_node">
Expand Down
3 changes: 2 additions & 1 deletion src/emoncms.cpp
Expand Up @@ -41,7 +41,8 @@ unsigned long emoncms_connection_error_count = 0;
void emoncms_publish(String data)
{
// We now create a URL for server data upload
String url = e_url;
String url = emoncms_path.c_str();
url += e_url;
url += "{";
// Copy across, data length
for (int i = 0; i < data.length(); ++i){
Expand Down
6 changes: 5 additions & 1 deletion src/web_server.cpp
Expand Up @@ -189,13 +189,15 @@ handleSaveEmoncms(AsyncWebServerRequest *request) {
}

config_save_emoncms(request->arg("server"),
request->arg("path"),
request->arg("node"),
request->arg("apikey"),
request->arg("fingerprint"));

char tmpStr[200];
snprintf(tmpStr, sizeof(tmpStr), "Saved: %s %s %s %s",
snprintf(tmpStr, sizeof(tmpStr), "Saved: %s %s %s %s %s",
emoncms_server.c_str(),
emoncms_path.c_str(),
emoncms_node.c_str(),
emoncms_apikey.c_str(),
emoncms_fingerprint.c_str());
Expand Down Expand Up @@ -310,6 +312,7 @@ handleStatus(AsyncWebServerRequest *request) {
s += ",\"ssid\":\"" + esid + "\"";
//s += ",\"pass\":\""+epass+"\""; security risk: DONT RETURN PASSWORDS
s += ",\"emoncms_server\":\"" + emoncms_server + "\"";
s += ",\"emoncms_path\":\"" + emoncms_path + "\"";
s += ",\"emoncms_node\":\"" + emoncms_node + "\"";
//s += ",\"emoncms_apikey\":\""+emoncms_apikey+"\""; security risk: DONT RETURN APIKEY
s += ",\"emoncms_fingerprint\":\"" + emoncms_fingerprint + "\"";
Expand Down Expand Up @@ -346,6 +349,7 @@ handleConfig(AsyncWebServerRequest *request) {
s += "\"ssid\":\"" + esid + "\",";
//s += "\"pass\":\""+epass+"\","; security risk: DONT RETURN PASSWORDS
s += "\"emoncms_server\":\"" + emoncms_server + "\",";
s += "\"emoncms_path\":\"" + emoncms_path + "\",";
s += "\"emoncms_node\":\"" + emoncms_node + "\",";
// s += "\"emoncms_apikey\":\""+emoncms_apikey+"\","; security risk: DONT RETURN APIKEY
s += "\"emoncms_fingerprint\":\"" + emoncms_fingerprint + "\",";
Expand Down