Hello,
I try to send data to mDash dashboard with my ESP32 running Mongoose OS with the demo code. Now when i try to use:
Dash.notify(‘Data’, {temperature: 12});
Code:
load('api_aws.js');
load('api_azure.js');
load('api_config.js');
load('api_dash.js');
load('api_events.js');
load('api_gcp.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_shadow.js');
load('api_timer.js');
load('api_sys.js');
load('api_watson.js');
let btn = Cfg.get('board.btn1.pin'); // Built-in button GPIO
let led = Cfg.get('board.led1.pin'); // Built-in LED GPIO number
let onhi = Cfg.get('board.led1.active_high'); // LED on when high?
let state = {on: false, btnCount: 0, uptime: 0}; // Device state
let online = false; // Connected to the cloud?
let setLED = function(on) {
let level = onhi ? on : !on;
GPIO.write(led, level);
print('LED on ->', on);
};
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
setLED(state.on);
let reportState = function() {
Shadow.update(0, state);
};
// Update state every second, and report to cloud if online
Timer.set(1000, Timer.REPEAT, function() {
state.uptime = Sys.uptime();
state.ram_free = Sys.free_ram();
print('online:', online, JSON.stringify(state));
if (online) reportState();
}, null);
// Set up Shadow handler to synchronise device state with the shadow state
Shadow.addHandler(function(event, obj) {
if (event === 'UPDATE_DELTA') {
print('GOT DELTA:', JSON.stringify(obj));
for (let key in obj) { // Iterate over all keys in delta
if (key === 'on') { // We know about the 'on' key. Handle it!
state.on = obj.on; // Synchronise the state
setLED(state.on); // according to the delta
} else if (key === 'reboot') {
state.reboot = obj.reboot; // Reboot button clicked: that
Timer.set(750, 0, function() { // incremented 'reboot' counter
Sys.reboot(500); // Sync and schedule a reboot
}, null);
}
}
reportState(); // Report our new state, hopefully clearing delta
}
});
if (btn >= 0) {
let btnCount = 0;
let btnPull, btnEdge;
if (Cfg.get('board.btn1.pull_up') ? GPIO.PULL_UP : GPIO.PULL_DOWN) {
btnPull = GPIO.PULL_UP;
btnEdge = GPIO.INT_EDGE_NEG;
} else {
btnPull = GPIO.PULL_DOWN;
btnEdge = GPIO.INT_EDGE_POS;
}
GPIO.set_button_handler(btn, btnPull, btnEdge, 20, function() {
state.btnCount++;
let message = JSON.stringify(state);
let sendMQTT = true;
if (Azure.isConnected()) {
print('== Sending Azure D2C message:', message);
Azure.sendD2CMsg('', message);
sendMQTT = false;
}
if (GCP.isConnected()) {
print('== Sending GCP event:', message);
GCP.sendEvent(message);
sendMQTT = false;
}
if (Watson.isConnected()) {
print('== Sending Watson event:', message);
Watson.sendEventJSON('ev', {d: state});
sendMQTT = false;
}
if (Dash.isConnected()) {
print('== Click!');
// TODO: Maybe do something else?
Dash.notify('Data', {temperature: 12.34});
sendMQTT = false;
}
// AWS is handled as plain MQTT since it allows arbitrary topics.
if (AWS.isConnected() || (MQTT.isConnected() && sendMQTT)) {
let topic = 'devices/' + Cfg.get('device.id') + '/events';
print('== Publishing to ' + topic + ':', message);
MQTT.pub(topic, message, 0 /* QoS */);
} else if (sendMQTT) {
print('== Not connected!');
}
}, null);
}
Event.on(Event.CLOUD_CONNECTED, function() {
online = true;
Shadow.update(0, {ram_total: Sys.total_ram()});
}, null);
Event.on(Event.CLOUD_DISCONNECTED, function() {
online = false;
}, null);
get this fatal error:
[Jun 17 15:11:13.422] Guru Meditation Error: Core 0 panic'ed (InstrFetchProhibited). Exception was unhandled.
[Jun 17 15:11:13.431] Core 0 register dump:
[Jun 17 15:11:13.433] PC : 0x00000000 PS : 0x00060030 A0 : 0x800fa8a2 A1 : 0x3ffc9d80
[Jun 17 15:11:13.440] A2 : 0x3ffb9a14 A3 : 0x3ffb4b74 A4 : 0x3ffb99d0 A5 : 0x00000000
[Jun 17 15:11:13.448] A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800fc731 A9 : 0x3ffc9d70
[Jun 17 15:11:13.456] A10 : 0x3ffb9a14 A11 : 0x00000000 A12 : 0x3ffb99d0 A13 : 0x00000000
[Jun 17 15:11:13.464] A14 : 0x00000067 A15 : 0x00000000 SAR : 0x0000000e EXCCAUSE: 0x00000014
[Jun 17 15:11:13.472] EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
[Jun 17 15:11:13.479]
[Jun 17 15:11:13.480] Backtrace: 0x00000000 0x400fa89f 0x400fba11 0x400fbb4d 0x400fcea2 0x400fd1b8 0x401d6b1a 0x401d6ffa 0x401d72d3 0x401d6b1a 0x401d7e52 0x401dafc1 0x401daff3 0x401ee94d 0x401d3031 0x400839ba 0x40083b81
[Jun 17 15:11:13.497]
[Jun 17 15:11:13.497] --- BEGIN CORE DUMP ---
[Jun 17 15:11:13.499] mos: catching core dump
Maybe someone has a solution for this.