diff --git a/http_interface.py b/http_interface.py index fca0bada23e6ab9e2f93e5621f59827fd1c6a28a..092059cc8cb03bf21fd6a979d87b63e850f1a32d 100644 --- a/http_interface.py +++ b/http_interface.py @@ -43,19 +43,14 @@ class MyServer(SimpleHTTPRequestHandler): # global ohmpiThread, status, run dic = json.loads(self.rfile.read(int(self.headers['Content-Length']))) - rdic = {} # response dictionnary - if dic['cmd'] == 'start': - #ohmpi.measure() - socket.send_string(json.dumps({ - 'cmd_id': cmd_id, - 'cmd': 'start' - })) - elif dic['cmd'] == 'stop': + rdic = {} # response dictionary + if dic['cmd'] == 'run_sequence': + payload = json.dumps({'cmd_id': cmd_id, 'cmd': 'run_sequence'}) + publish.single(payload=payload, **publisher_config) + elif dic['cmd'] == 'interrupt': # ohmpi.stop() - socket.send_string(json.dumps({ - 'cmd_id': cmd_id, - 'cmd': 'stop' - })) + payload = json.dumps({'cmd_id': cmd_id, 'cmd': 'interrupt'}) + publish.single(payload=payload, **publisher_config) elif dic['cmd'] == 'getData': # get all .csv file in data folder fnames = [fname for fname in os.listdir('data/') if fname[-4:] == '.csv'] diff --git a/index.html b/index.html index ee10373ba50e0f40cc12c95a2e7f94e15db2b7f6..db104d009f47532bc3ed3fcbdd304433b72c4496 100644 --- a/index.html +++ b/index.html @@ -18,15 +18,15 @@ <h1>OhmPi Acquisition Board</h1> <!-- nb stacks, on-time --> <button id="update_settingsBtn" type="button" class="btn btn-secondary" data-toggle="modal" data-target="#exampleModal">Settings</button> - <button id='startBtn' type="button" class="btn btn-primary">Start</button> - <button id='stopBtn' type="button" class="btn btn-warning">Stop</button> + <button id='runBtn' type="button" class="btn btn-primary">▶</button> + <button id='stopBtn' type="button" class="btn btn-warning">◼</button> <!-- upload button for csv which display the table ABMN --> <button id="removeDataBtn" type="button" class="btn btn-danger">Clear data</button> <button id="getDataBtn" type="button" class="btn btn-info">Get data</button> <div class="form-check"> <input id="dataRetrievalCheck" class="form-check-input" type="checkbox" value=""> <label class="form-check-label" for="dataRetrievalCheck"> - Automaticaly get data every 1 second + Automaticaly get data every 1 secondStart </label> </div> <div id='output'>Status: idle</div> @@ -161,21 +161,21 @@ xhr.send(query) } - // start button - function startBtnFunc() { - sendCommand('{"cmd": "start"}', function(x) { + // run button + function runBtnFunc() { + sendCommand('{"cmd": "run_sequence"}', function(x) { console.log(x['status']) if (x['status'] == 'running') { output.innerHTML = 'Status: measuring...' } }) } - let startBtn = document.getElementById('startBtn') - startBtn.addEventListener('click', startBtnFunc) + let runBtn = document.getElementById('runBtn') + runBtn.addEventListener('click', runBtnFunc) - // stop button + // interrupt button function stopBtnFunc() { - sendCommand('{"cmd": "stop"}', function(x) { + sendCommand('{"cmd": "interrupt"}', function(x) { output.innerHTML = 'Status: ' + x['status'] clearInterval(interv) getData()