diff --git a/public/js/feeds.js b/public/js/feeds.js index f10c634..2d05c4d 100644 --- a/public/js/feeds.js +++ b/public/js/feeds.js @@ -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) { @@ -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; @@ -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); + } } }); } @@ -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]; diff --git a/public/views/feeds.php b/public/views/feeds.php index ba4e99a..6a43a7f 100644 --- a/public/views/feeds.php +++ b/public/views/feeds.php @@ -81,9 +81,11 @@ class="btn btn-outline-info"

Graph: {{ shared.selectedFeedNames }}

-

{{ shared.error }}

- -
+

{{ shared.errorTitle }}

+ {{ shared.error }} +
+
{{local.tooltip.contents}} diff --git a/python-client/fake-input.py b/python-client/fake-input.py index 2e60c76..df8f9f2 100644 --- a/python-client/fake-input.py +++ b/python-client/fake-input.py @@ -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) @@ -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) \ No newline at end of file + time.sleep(10)