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

Feature/issue 23 feed not found #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions public/js/feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ var STORE = {
selectedFeeds: [],
view: 'list',
status: 'ready',
error: ''
error: '',
errorTitle: ''
},
// edit the shared store's state with internal functions...
toggleCollapsed: function(tag, state) {
Expand Down Expand Up @@ -263,6 +264,10 @@ var STORE = {
LOGGER.verbose('STORE: setStatus() did not change status. Was already set to', status);
}
},
setErrorTitle: function(msg) {
this.state.errorTitle = msg;
LOGGER.verbose('STORE: setErrorTitle() triggered with', msg);
},
setError: function(msg) {
this.setStatus('error');
this.state.error = msg;
Expand Down Expand Up @@ -406,26 +411,39 @@ var MQTT = (function(Store, Session, Settings, Endpoints, Logger, RefreshRate, U
timer.stop(); // stop the timeout counter
var response = JSON.parse(message.toString()); // decode stream
Logger.info('MQTT: received message for: ', response.request.action);
Logger.debug('Taken', timer.timeTaken() + 'ms','for partner mqtt (sub.py) client to respond with', response.request.action)
Logger.debug('Taken', timer.timeTaken() + 'ms','for partner mqtt (sub.py) client to respond with', response.request.action);
var result = response.result;
switch(response.request.action) {
case Endpoints.feedlist:
Logger.debug('STORE: setNodes()');
Store.setFeeds(result);
break;
case Endpoints.graph:
GRAPH.plot(response);
break;
case Endpoints.saveFeed:
Logger.info('@todo: respond to feed->set Endpoints call');
Logger.debug('API: feed->set()');
break;
case Endpoints.deleteFeed:
Logger.info('@todo: respond to feed->delete Endpoints call');
Logger.debug('API: feed->delete()');
break;
default:
Logger.debug('MQTT: cannot respond to unrecognized action ', response.request.action);
if(result.success === false) {
Logger.debug('Error:', result.message, 'Original Request:', response.request);
// stop the auto reload of data
interruptPublishInterval();
Store.setStatus('error');
Store.setErrorTitle('API Error');
Store.setError('"' + response.request.action + '" failed. Please update your EmonCMS install to handle the required API requests.');
// put the graph view back to the list view
if(Store.state.view === 'graph') {
// Store.setView('list');
}
} else {
switch(response.request.action) {
case Endpoints.feedlist:
Logger.debug('STORE: setNodes()');
Store.setFeeds(result);
break;
case Endpoints.graph:
GRAPH.plot(response);
break;
case Endpoints.saveFeed:
Logger.info('@todo: respond to feed->set Endpoints call');
Logger.debug('API: feed->set()');
break;
case Endpoints.deleteFeed:
Logger.info('@todo: respond to feed->delete Endpoints call');
Logger.debug('API: feed->delete()');
break;
default:
Logger.debug('MQTT: cannot respond to unrecognized action ', response.request.action);
}
}
});
}
Expand Down Expand Up @@ -589,6 +607,9 @@ var GRAPH = (function (Store, Endpoints, Mqtt, Logger){

// loop through results
var data = [];
if(response.result == "Feed does not exist") {
// api doesn't support
}
for (index in response.result) {
// plot the data points
var result = response.result[index];
Expand Down
8 changes: 5 additions & 3 deletions public/views/feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ class="btn btn-outline-info"
<transition name="fade">
<h2 class="animate" v-if="false && shared.selectedFeedNames !== ''">Graph: {{ shared.selectedFeedNames }} </h2>
</transition>
<h4 v-if="shared.status === 'error'"> {{ shared.error }} </h4>

<div style="opacity:.8;z-index:2" class="p-2 font-weight-bold position-absolute bg-light"
<div v-if="shared.status === 'error'" class="alert alert-warning">
<h4 class="alert-heading"> {{ shared.errorTitle }} </h4>
{{ shared.error }}
</div>
<div id="tooltip" style="opacity:.8;z-index:2" class="p-2 font-weight-bold position-absolute bg-light"
:style="{top: local.tooltip.top, left: local.tooltip.left, display: local.tooltip.show ? 'block': 'none'}"
>
{{local.tooltip.contents}}
Expand Down
8 changes: 4 additions & 4 deletions python-client/fake-input.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# load settings from .env file
_dir = path.dirname(path.dirname(path.abspath(__file__)))

if path.isfile(path.join(_dir, 'remoteaccess.env')) :
dotenv_path = path.join(_dir, 'remoteaccess.env')
if path.isfile(path.join(_dir, 'remoteaccess.env.dev')) :
dotenv_path = path.join(_dir, 'remoteaccess.env.dev')
else:
print('remoteaccess.env not found')
sys.exit(0)
Expand All @@ -38,10 +38,10 @@ def get_data(url):
# random integer between 1 and 100
value = random.randint(1,101)
# add url parameters to url
url = "%s?node=emontx&json={power1:%s}&apikey=%s" % (base_url, value, apikey)
url = "%s?node=emontx&json={power2:%s}&apikey=%s" % (base_url, value, apikey)
# request http response
response = get_data(url)
# output response from http request
print("%s - posted: %s" % (response, value))
# wait 10s before iterating
time.sleep(10)
time.sleep(10)