-->
Page 1 of 1

NodeMCU Not uploading to IBM Cloud

PostPosted: Sat Mar 28, 2020 7:26 pm
by sp500
Hi, I'm trying to connect my NodeMCU to IBM Bluemix. However, everytime I upload the code from Arduino IDE. The program stalls at trying to connect to IBM Cloud and just prints out periods. Any help appreciated

Here's the example code I used. I tried with both quick start any by plugging in the Device and Org info, but no luck either way:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

//-------- Customise these values -----------
const char* ssid = "<yourSSID>";
const char* password = "<yourPassword>";

#define ORG "quickstart" // "quickstart" or use your organisation
#define DEVICE_ID "Test5"
#define DEVICE_TYPE "ESP8266" // your device type or not used for "quickstart"
#define TOKEN "xxxxxxxxxxxxx" // your device token or not used for "quickstart"
//-------- Customise the above values --------

char server[] = ORG ".messaging.internetofthings.ibmcloud.com";
char topic[] = "iot-2/evt/status/fmt/json";
char authMethod[] = "use-token-auth";
char token[] = TOKEN;
char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID;

WiFiClientSecure wifiClient;
PubSubClient client(server, 8883, wifiClient);

void setup() {
Serial.begin(115200); Serial.println();

Serial.print("Connecting to "); Serial.print(ssid);
if (strcmp (WiFi.SSID().c_str(), ssid) != 0) {
WiFi.begin(ssid, password);
}
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi connected, IP address: "); Serial.println(WiFi.localIP());

Serial.println("View the published data on Watson at: ");
if (ORG == "quickstart") {
Serial.println("https://quickstart.internetofthings.ibmcloud.com/#/device/" DEVICE_ID "/sensor/");
} else {
Serial.println("https://" ORG ".internetofthings.ibmcloud.com/dashboard/#/devices/browse/drilldown/" DEVICE_TYPE "/" DEVICE_ID);
}
}

void loop() {
if (!!!client.connected()) {
Serial.print("Reconnecting client to "); Serial.println(server);
while ( ! (ORG == "quickstart" ? client.connect(clientId) : client.connect(clientId, authMethod, token))) {
Serial.print(".");
delay(500);
}
Serial.println();
}

String payload = "{\"d\":{\"myName\":\"ESP8266.Test5\",\"counter\":";
payload += millis() / 1000;
payload += "}}";

Serial.print("Sending payload: "); Serial.println(payload);

if (client.publish(topic, (char*) payload.c_str())) {
Serial.println("Publish ok");
} else {
Serial.println("Publish failed");
}

delay(5000);
}

Re: NodeMCU Not uploading to IBM Cloud

PostPosted: Sun Mar 29, 2020 7:49 pm
by davydnorris
Pretty sure you need to change the TOKEN and DEVICETYPE to be empty strings for quickstart

Re: NodeMCU Not uploading to IBM Cloud

PostPosted: Sun Mar 29, 2020 8:43 pm
by sp500
Thanks for the help davydnorris but still not working. I also tried changing DEVICEID to empty string but no luck. Also I don't really want to use quickstart, I just copied the original code.

Re: NodeMCU Not uploading to IBM Cloud

PostPosted: Mon Mar 30, 2020 9:52 pm
by davydnorris
Device ID must be exactly the same as the name you registered on the IBM Cloud Quickstart page