I tried to connect to IoT platform from ESP32 through MQTT.
My code as below. There is no problem when I use Adafruit MQTT broker.
But I got a "Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited)" error when tried to send MQTT to this IoT platform.
Is it due to the key is too long? Is there any solution?
Code: Select all
#include "WiFi.h"
#include "PubSubClient.h"
const char* ssid = "*****";
const char* password = "*****";
const char* mqtt_server = "mqtt.favoriot.com";
const char* username = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImlsemFtYWxwcyIsInJlYWRfd3JpdGUiOnRydWUsImlhdCI6MTUyODQ0ODQwN30.7ChIJzlW0Ja7QGR_sO6T04yh3pCY9tEqPbf********";
const char* passkey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImlsemFtYWxwcyIsInJlYWRfd3JpdGUiOnRydWUsImlhdCI6MTUyODQ0ODQwN30.7ChIJzlW0Ja7QGR_sO6T04yh3pCY9tEqPbf********";
const char* topic = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImlsemFtYWxwcyIsInJlYWRfd3JpdGUiOnRydWUsImlhdCI6MTUyODQ0ODQwN30.7ChIJzlW0Ja7QGR_sO6T04yh3pCY9tEqPbf********/all";
WiFiClient espClient;
PubSubClient client(espClient);
void mqttconnect() {
while (!client.connected()) {
Serial.print("MQTT connecting ...");
String clientId = "ESP32";
if (client.connect(clientId.c_str(),username,passkey)) {
Serial.println("connected");
} else {
Serial.print("failed, status code =");
Serial.print(client.state());
Serial.println("try again in 5 seconds");
delay(5000);
}
}
}
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
client.setServer(mqtt_server, 1883);
}
void loop() {
if (!client.connected()) {
mqttconnect();
}
String json = "{\"device_developer_id\":\"deviceDefault@ilzamalps\",\"data\":{\"humidity\":\"80\",\"temperature\":\"30\"}}";
client.publish(topic,json.c_str());
delay(30000);
}
Code: Select all
Connecting to zamii@unifi
..
WiFi connected
IP address:
192.168.0.148
MQTT connecting ...Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited)
. Exception was unhandled.
Register dump:
PC : 0x00000000 PS : 0x00060030 A0 : 0x800d21a8 A1 : 0x3ffd0ca0
A2 : 0x3ffc3224 A3 : 0x3ffd0cac A4 : 0x00000000 A5 : 0x00000155
A6 : 0x00000003 A7 : 0x00000000 A8 : 0x800d2090 A9 : 0x00000002
A10 : 0x3ffc32d4 A11 : 0x3ffc322a A12 : 0x00000158 A13 : 0xfb792634
A14 : 0xfb792634 A15 : 0x3ffc3b14 SAR : 0x00000018 EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x400d210d LEND : 0x400d211c LCOUNT : 0x00000000
Backtrace: 0x00000000:0x3ffd0ca0 0x400d21a5:0x3ffd0cd0 0x400d2266:0x3ffd0d10 0x400d13c8:0x3ffd0d40 0x400d14b3:0x3ffd0d70 0x4010cf50:0x3ffd0da0
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078ad0