NodeMcu Can't Connect to Thinger Platform

Hello all,

I tried to connect NodeMcu with Thinger platform using arduino IDE.
First, i make device definition, device resource, and also dashboard in Thinger platform.
Just using sample code that i’ve found in this forum.
This is the code i use :

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingerWifi.h>
#include <SoftwareSerial.h>

#define USERNAME “xxxxxxxxxxx”
#define DEVICE_ID “xxxxxxxxxxxx”
#define DEVICE_CREDENTIAL “xxxxxxxxxxxx”

#define SSID “mySSID”
#define SSID_PASSWORD “mypassword”

#define sakelar1 5
#define sakelar2 15

ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
Serial.begin(115200);
//Set output mode for all IO pins
pinMode(sakelar1, OUTPUT);
pinMode(sakelar2, OUTPUT);
delay(10);
thing.add_wifi(SSID, SSID_PASSWORD);
thing[“output1”] << [](pson& in){ digitalWrite(sakelar1, in ? HIGH : LOW); };
thing[“output2”] << [](pson& in){ digitalWrite(sakelar2, in ? HIGH : LOW); };
}

void loop() {
thing.handle();
}

After verify/compilation on arduino IDE is done, i monitor the process using debug console.
The result looks strange

Does anyone experienced the same issue?
Or did i missed some stuff in the code?

Thanks.

Hi, this code is not necessary for a NodeMCU. You should use the example from the ESP8266 that defines the thing as ThingerESP8266.

Best.

Hi,

I’ve changed it to ThingerESP8266 thing and when i checked on thinger platform, my device is still offline. Here’s my code change :

//Using cloud server on “thingerio”

#include <ESP8266WiFi.h>
#include <ThingerWifi.h>
#include <ThingerESP8266.h>

#define USERNAME “envinix”
#define DEVICE_ID “SoketPintar”
#define DEVICE_CREDENTIAL “*************”

#define SSID “mySSID”
#define SSID_PASSWORD “myPASSWD”

#define output1 5
#define output2 15

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
Serial.begin(115200);
Serial.println();
//Set output mode for all IO pins
pinMode(output1, OUTPUT);
pinMode(output2, OUTPUT);
delay(10);
thing.add_wifi(SSID, SSID_PASSWORD);
Serial.print(“Connecting”);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();

Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());

//Serial.print(“connecting”);
thing[“Sakelar 1”] << [](pson& in){ digitalWrite(output1, in ? HIGH : LOW); };
thing[“Sakelar 2”] << [](pson& in){ digitalWrite(output2, in ? HIGH : LOW); };
}

void InitWifi() {
Serial.println(“Connecting to AP …”);
// attempt to connect to WiFi network

// WiFi.begin(WIFI_AP, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(“Connected to AP”);
}

void loop() {
InitWifi();
thing.handle();
}

The output on debug console only shows :
Connecting to AP…
Connected to AP

I just curious, what’s inside “thing.handle();” ? could you explain?
I’ve tried many times but still cannot connect to the platform.

Cheers.

Hi, try this, of course you need to change username, device, credential, ssid and password

#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>

#define USERNAME "your_user_name"
#define DEVICE_ID "your_device_id"
#define DEVICE_CREDENTIAL "your_device_credential"

#define SSID "your_wifi_ssid"
#define SSID_PASSWORD "your_wifi_ssid_password"

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
  pinMode(BUILTIN_LED, OUTPUT);

  thing.add_wifi(SSID, SSID_PASSWORD);

  // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
  thing["led"] << digitalPin(BUILTIN_LED);

  // resource output example (i.e. reading a sensor value)
  thing["millis"] >> outputValue(millis());

  // more details at http://docs.thinger.io/arduino/
}

void loop() {
  thing.handle();
}

This is the example sketch, must work without issues, after that you can modify this sketch according your needs, I see that the code you post has a couple of differences, I recomend you check if your libraries are updated.

Hope this helps you.

Hi ega,

Thanks for your hint. Now my device can connect to thinger platform with this basic code.
I will try to improve code to suit our solution.

Cheers.

Hello! I have tried using this sketch, I do not know why my device is still not connected. I tried all my nodeMCUs even the new ones I bought, my device still doesn’t connect. Yes I changed all username, device, credential, ssid and password, I even used a mobile hotspot from my phone other than from a wifi router. What could be this issue? Your help if very much appreciated.

Hi

Put at the very first line of your sketch the next line:

#define DEBUG

This will show on serial console why it can’t connect.

Paste the serial console response to see what is going on.

Hope this helps.

thanks! I figured it out!

Do you know where can I add more devices via donation? I want to add two buckets too!

Interesting