Sorry, link reports ??
I doing like this.
- create a new project in platformIO.
- 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;
}
- 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
-
Connect nodeMcu to USB on computer and upload application
-
Attach serial monitor
-
Use Restman to turn led on/of a couple of times. Works.
-
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