Feedback on "Things" example

Hi

I’ve decided to make a “Thing”. I have a nodeMcu and installed PlatformIO.
From github I’ve copied the PlatformIO version of LED.cpp and all other necessary files.

Compiling it gives a lot of warnings, so I guess the example not are up to date.

Running the example I can, by using “RestMan” turn Led on and off and read status. When asking for properties from the “Thing” result is not according to API specification.

Worse is my “Thing” crashes after running for a while …


Exception (28):
epc1=0x4020c7a9 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000028 depc=0x00000000

ctx: sys
sp: 3fffdac0 end: 3fffffb0 offset: 01a0

stack>>>
3fffdc60: 3fff1a24 3fffdca0 00000008 000005b4
3fffdc70: 00000010 3fff1a60 3fff1a60 4020ae03
3fffdc80: 3ffe93e4 00000000 3fff1a60 4020ae4f
3fffdc90: 00000000 3fff1afc 3fff1a60 4020ae81


Now I planning to write a Adapter (or copy example adapter) for my “Thing”
I would like some rekommendation on how to set up a development environment for this work. I really would like to have a debugging environment where I can set breakpoints and step through my adapter. Using “printf” as only mean of debugging, :frowning:

Do you know the exact reference of your MCU on your board?

My ESP8266 was stable enough for me, I used the RGBlamp example during days…

Hi

I am using nodeMcu2 with ESP-12E,

I’ve have worked more on this project. My conclusion is that it is during “pairing” with gateway the module crashes, Otherwise it seems okay.

I have seen some other reports about that …

please link reports and see if there is a way to reproduce

Sorry, link reports ??

I doing like this.

  1. create a new project in platformIO.
  2. Copy led example

 **
 * Simple server compliant with Mozilla's proposed WoT API
 * Originally based on the HelloServer example
 * Tested on ESP8266, ESP32, Arduino boards with WINC1500 modules (shields or
 * MKR1000)
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <Arduino.h>
#include "Thing.h"
#include "WebThingAdapter.h"

//TODO: Hardcode your wifi credentials here (and keep it private)2
const char* ssid = "";
const char* password = "";

#if defined(LED_BUILTIN)
const int ledPin = LED_BUILTIN;
#else
const int ledPin = 13;  // manually configure LED pin
#endif

WebThingAdapter* adapter;

const char* ledTypes[] = {"OnOffSwitch", "Light", nullptr};
ThingDevice led("led", "Built-in LED", ledTypes);
ThingProperty ledOn("on", "", BOOLEAN, "OnOffProperty");

bool lastOn = false;

void setup(void){
   pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  Serial.begin(115200);
  Serial.println("");
  Serial.print("Connecting to \"");
  Serial.print(ssid);
  Serial.println("\"");
  #if defined(ESP8266) || defined(ESP32)
  WiFi.mode(WIFI_STA);
  #endif
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  bool blink = true;
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
      digitalWrite(ledPin, blink ? LOW : HIGH); // active low led
      blink = !blink;
 }
 digitalWrite(ledPin, HIGH); // active low led

 Serial.println("");
 Serial.print("Connected to ");
 Serial.println(ssid);
 Serial.print("IP address: ");
 Serial.println(WiFi.localIP());
 adapter = new WebThingAdapter("w25", WiFi.localIP());

  led.addProperty(&ledOn);
  adapter->addDevice(&led);
  adapter->begin();
  Serial.println("HTTP server started");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.print("/things/");
  Serial.println(led.id);
}

void loop(void){
 adapter->update();
 bool on = ledOn.getValue().boolean;
 digitalWrite(ledPin, on ? LOW : HIGH); // active low led
 if (on != lastOn) {
    Serial.print(led.id);
    Serial.print(": ");
    Serial.println(on);
 }
  lastOn = on;
}

  1. Modify platformIo.ino

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[global]
lib_deps =
   https://github.com/mozilla-iot/webthing-arduino.git
   ArduinoJson

 [env:nodemcuv2]
 platform = espressif8266
 board = nodemcuv2
 framework = arduino
 lib_deps =
     ${global.lib_deps}
     ESP Async WebServer
 lib_ignore =
     ArduinoMDNS
     WiFi101
 lib_ldf_mode = deep+
 monitor_port = COM4
  monitor_speed = 115200
  1. Connect nodeMcu to USB on computer and upload application

  2. Attach serial monitor

  3. Use Restman to turn led on/of a couple of times. Works.

  4. Wait, 10 min,30 min 90 min, what ever. Stack dump is shown in the terminal window. nodeMcu not responding to RestMan

Beginning of dump below.

    -----------
    --- Miniterm on COM4  115200,8,N,1 ---
    --- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
    ..
    Connected to atHome
    IP address: 192.168.0.129
    MDNS responder started
    HTTP server started
    http://192.168.0.129/things/led
    led: 1

Exception (28):
epc1=0x4020c831 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000028 depc=0x00000000

ctx: sys
sp: 3fffdac0 end: 3fffffb0 offset: 01a0

>>>stack>>>
3fffdc60:  3fff1a1c 3fffdca0 00000008 000005b4
3fffdc70:  00000010 3fff1a58 3fff1a58 4020ae8b
3fffdc80:  3ffe9394 00000000 3fff1a58 4020aed7
3fffdc90:  00000000 3fff1af4 3fff1a58 4020af09

Hi

I still have problem with instability. Since last I have build a breadboard for my nodeMcu so I have control of all not used io ports.

Nothing have changed. I can run 10 minutes, 1 hour, 1 day, but soner or later it crashes.

Can anybody please verify/object to what I am saying???
For me stability is quite fundamental if I am going to trust this…

Instead of using RestMan for sending commands to toggle the LED, have you tried running the Mozilla Things Gateway on your laptop or installed it on an RPi? You could set up some clock based rules to test on then off every five min or so while having the serial monitor connected. Perhaps update the printf output to put a time stamp on the toggle state. I have not seen issues when controlling the NodeMCU from a Raspberry Pi running the Things Gateway application, but I have not done extensive testing.

My experience how to find this kind of problems, is to reduce “unknowns”. That’s why I have disconnected the gateway from the device, (using restman once to set state of device), no serial debug port connected etc. Just running the device in a “defined” state and expecting it to stay in that state for a long time… (we are talking days).

If community states that “it works for them”, I will get more nodeMcu modules and test. It can be bad soldering or simular problems on my module.

There appears to be an issue where some boards have too little memory to support the massive staticjsonbuffers I use in the adapter. If you switch some StaticJsonBuffers to DynamicJsonBuffers you may get better results and I’ll be looking into this further whenever I get time.