NodeMcu Can't Connect to Thinger Platform


#1

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.


#2

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

Best.


#3

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.


#4

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.


#5

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.