-
Notifications
You must be signed in to change notification settings - Fork 77
PushButton PressedEvent #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hmm, the code looks right. What kind of device are you running on? |
The "Sketch" itself runs on a esp8266 - WeMos D1 mini. |
Ok, I have an ESP8266 I can test with in a couple days. However, I’d strongly recommend you update your gateway to 1.0.0 before we shut down all of our old Mozilla infrastructure on Monday. |
The problem is that all of your events had the same default timestamp. Here is an example of how to fix that, using the ESPDateTime library: #include "wifisecret.h"
#define LARGE_JSON_BUFFERS 1
#include <Arduino.h>
#include <ESPDateTime.h>
#include <Thing.h>
#include <WebThingAdapter.h>
const uint8_t buttonPin = 4;
WebThingAdapter *adapter;
//https://webthings.io/schemas/#PushButton
const char *remoteTypes[] = {"PushButton", nullptr};
ThingDevice remote("urn:dev:ops:mypushbutton", "Push Button I", remoteTypes);
ThingEvent pressed("pressed",
"PressedEvent",
BOOLEAN, "PressedEvent");
ThingProperty button("button", "PushButton", BOOLEAN, "PushedProperty");
void setup(void)
{
pinMode(buttonPin, INPUT);
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
adapter = new WebThingAdapter("push-button", WiFi.localIP());
remote.description = "A Webthings PushButton";
button.title = "PushButton";
remote.addProperty(&button);
remote.addEvent(&pressed);
adapter->addDevice(&remote);
adapter->begin();
Serial.println("HTTP server started");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.print("/things/");
Serial.println(remote.id);
randomSeed(analogRead(0));
DateTime.begin();
if (!DateTime.isTimeValid()) {
Serial.println("Failed to get time from server.");
}
}
unsigned long oldMillis = 0;
bool test = true;
void loop(void)
{
if (millis() >= oldMillis + 5000) {
if (!DateTime.isTimeValid()) {
Serial.println("Failed to get time from server, retry.");
DateTime.begin();
} else {
Serial.println("Force Event!");
oldMillis = millis();
test = !test;
button.setValue({.boolean = test});
ThingEventObject *ev = new ThingEventObject(
"pressed",
BOOLEAN,
{.boolean = true},
DateTime.formatUTC(DateFormatter::ISO8601)
);
remote.queueEventObject(ev);
Serial.println();
}
}
adapter->update();
} |
I tryed to create a PushButton Device. Basically a remote:
What works:
The Node can be found by discovery. WebThings Gateway receives every 5 seconds a button change.
What does not work:
A PressedEvent should occur every 5 seconds. But it does not.
Does someone know what i made wrong?
With kind regards,
Mia
The text was updated successfully, but these errors were encountered: