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 …
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,
**
* 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;
}
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.