Skip to content

Commit 3606319

Browse files
committed
Remove symlinks, since Arduino doesn't like them.
1 parent 13bac6b commit 3606319

File tree

10 files changed

+862
-10
lines changed

10 files changed

+862
-10
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Package project
1616
run: |
1717
mkdir webthing-arduino
18-
cp -rL CODE_OF_CONDUCT.md *.h LICENSE README.md library.* docs/ examples/ webthing-arduino/
18+
cp -r CODE_OF_CONDUCT.md *.h LICENSE README.md library.* docs/ examples/ webthing-arduino/
1919
zip -r webthing-arduino.zip webthing-arduino/
2020
- name: Create Release
2121
id: create_release

examples/PlatformIO/AsyncProperty/src/main.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* Test of webthing-arduino with async behavior. Works with
3+
* thing-url-adapter.
4+
*/
5+
6+
#define LARGE_JSON_BUFFERS 1
7+
8+
#include <Arduino.h>
9+
#include <Thing.h>
10+
#include <WebThingAdapter.h>
11+
12+
const char *ssid = "XXXXXXX";
13+
const char *password = "XXXXXXX";
14+
15+
int loginCounter;
16+
WebThingAdapter *adapter;
17+
// Forward declaration
18+
void onOffChanged(ThingPropertyValue newValue);
19+
void textChanged(ThingPropertyValue newValue);
20+
void numberChanged(ThingPropertyValue newValue);
21+
22+
const char *asyncProperties[] = {"asyncProperty", nullptr};
23+
ThingDevice textDisplay("asyncProperty", "AsyncProperty Test",
24+
asyncProperties);
25+
ThingProperty text("text", "", STRING, nullptr, textChanged);
26+
ThingProperty onOff("bool", "", BOOLEAN, "OnOffProperty", onOffChanged);
27+
ThingProperty number("number", "", NUMBER, nullptr, numberChanged);
28+
29+
String message = "message";
30+
String lastMessage = message;
31+
boolean lastState = false;
32+
int lastNumber = 0;
33+
34+
// Callback functions
35+
//
36+
void onOffChanged(ThingPropertyValue newValue) {
37+
Serial.print("On/Off changed to : ");
38+
Serial.println(newValue.boolean);
39+
}
40+
41+
void textChanged(ThingPropertyValue newValue) {
42+
Serial.print("New message : ");
43+
Serial.println(*newValue.string);
44+
}
45+
46+
void numberChanged(ThingPropertyValue newValue) {
47+
Serial.print("New number : ");
48+
Serial.println(newValue.number);
49+
}
50+
51+
void setup() {
52+
Serial.begin(115200);
53+
54+
// counter used for login time out, function needed with ESP32
55+
loginCounter = 0;
56+
57+
#if defined(ESP8266) || defined(ESP32)
58+
WiFi.mode(WIFI_STA);
59+
#endif
60+
61+
Serial.print("Connecting : ");
62+
WiFi.begin(ssid, password);
63+
64+
// Wait for connection
65+
while (WiFi.status() != WL_CONNECTED) {
66+
67+
// more than 5 sec wait, try to login again.
68+
if (loginCounter == 10) {
69+
loginCounter = 0;
70+
WiFi.begin(ssid, password);
71+
} else {
72+
loginCounter++;
73+
}
74+
delay(500);
75+
Serial.print(".");
76+
}
77+
78+
Serial.println("");
79+
Serial.print("Connected to ");
80+
Serial.println(ssid);
81+
Serial.print("IP address: ");
82+
Serial.println(WiFi.localIP());
83+
84+
adapter = new WebThingAdapter("asyncProperty", WiFi.localIP());
85+
86+
ThingPropertyValue value;
87+
value.string = &message;
88+
text.setValue(value);
89+
90+
textDisplay.addProperty(&text);
91+
textDisplay.addProperty(&onOff);
92+
textDisplay.addProperty(&number);
93+
adapter->addDevice(&textDisplay);
94+
adapter->begin();
95+
}
96+
97+
void loop() {
98+
delay(500);
99+
adapter->update();
100+
}

examples/PlatformIO/BME280/src/main.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
WiFi Web Server LED control via web of things (e.g., iot.mozilla.org gateway)
3+
based on WiFi101.h example "Provisioning_WiFiWebServer.ino"
4+
5+
A simple web server that lets you control an LED via the web.
6+
This sketch will print the IP address of your WiFi device (once connected)
7+
to the Serial monitor. From there, you can open that address in a web browser
8+
to turn on and off the onboard LED.
9+
10+
You can also connect via the Things Gateway http-on-off-wifi-adapter.
11+
12+
If the IP address of your shield is yourAddress:
13+
http://yourAddress/H turns the LED on
14+
http://yourAddress/L turns it off
15+
16+
This example is written for a network using WPA encryption. For
17+
WEP or WPA, change the Wifi.begin() call accordingly.
18+
19+
Circuit:
20+
* WiFi using Microchip (Atmel) WINC1500
21+
* LED attached to pin 1 (onboard LED) for SAMW25
22+
* LED attached to pin 6 for MKR1000
23+
24+
created 25 Nov 2012
25+
by Tom Igoe
26+
27+
updates: dh, kg 2018
28+
*/
29+
30+
#define LARGE_JSON_BUFFERS 1
31+
32+
#include <Arduino.h>
33+
#include <BME280.h>
34+
#include <BME280I2C.h>
35+
#include <SPI.h>
36+
#include <Wire.h>
37+
#include <WiFi101.h>
38+
#include <Thing.h>
39+
#include <WebThingAdapter.h>
40+
41+
#ifndef PIN_STATE_HIGH
42+
#define PIN_STATE_HIGH HIGH
43+
#endif
44+
#ifndef PIN_STATE_LOW
45+
#define PIN_STATE_LOW LOW
46+
#endif
47+
48+
WebThingAdapter *adapter;
49+
50+
const char *bme280Types[] = {"TemperatureSensor", nullptr};
51+
ThingDevice weather("bme280", "BME280 Weather Sensor", bme280Types);
52+
ThingProperty weatherTemp("temperature", "", NUMBER, "TemperatureProperty");
53+
ThingProperty weatherHum("humidity", "", NUMBER, nullptr);
54+
ThingProperty weatherPres("pressure", "", NUMBER, nullptr);
55+
56+
BME280I2C::Settings
57+
settings(BME280::OSR_X1, BME280::OSR_X1, BME280::OSR_X1,
58+
BME280::Mode_Forced, BME280::StandbyTime_1000ms,
59+
BME280::Filter_Off, BME280::SpiEnable_False,
60+
(BME280I2C::I2CAddr)0x76 // I2C address. I2C specific.
61+
);
62+
63+
BME280I2C bme(settings);
64+
65+
void readBME280Data() {
66+
float temp(NAN), hum(NAN), pres(NAN);
67+
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
68+
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
69+
bme.read(pres, temp, hum, tempUnit, presUnit);
70+
71+
ThingPropertyValue value;
72+
value.number = pres;
73+
weatherPres.setValue(value);
74+
value.number = temp;
75+
weatherTemp.setValue(value);
76+
value.number = hum;
77+
weatherHum.setValue(value);
78+
}
79+
80+
void setup() {
81+
// Initialize serial:
82+
// Serial.begin(9600);
83+
84+
// check for the presence of the shield:
85+
// Serial.print("Configuring WiFi shield/module...\n");
86+
if (WiFi.status() == WL_NO_SHIELD) {
87+
// Serial.println("WiFi shield not present");
88+
// don't continue:
89+
while (true)
90+
;
91+
}
92+
93+
// configure the LED pin for output mode
94+
pinMode(LED_BUILTIN, OUTPUT);
95+
96+
Wire.begin();
97+
while (!bme.begin()) {
98+
// Serial.println("Could not find BME280I2C sensor!");
99+
delay(1000);
100+
}
101+
102+
// Serial.println("Starting in provisioning mode...");
103+
// Start in provisioning mode:
104+
// 1) This will try to connect to a previously associated access point.
105+
// 2) If this fails, an access point named "wifi101-XXXX" will be created,
106+
// where XXXX
107+
// is the last 4 digits of the boards MAC address. Once you are connected
108+
// to the access point, you can configure an SSID and password by
109+
// visiting http://wifi101/
110+
WiFi.beginProvision();
111+
112+
while (WiFi.status() != WL_CONNECTED) {
113+
// wait while not connected
114+
115+
// blink the led to show an unconnected status
116+
digitalWrite(LED_BUILTIN, PIN_STATE_HIGH);
117+
delay(500);
118+
digitalWrite(LED_BUILTIN, PIN_STATE_LOW);
119+
delay(500);
120+
}
121+
122+
// connected, make the LED stay on
123+
digitalWrite(LED_BUILTIN, PIN_STATE_HIGH);
124+
adapter = new WebThingAdapter("weathersensor", WiFi.localIP());
125+
126+
weatherTemp.unit = "celsius";
127+
weather.addProperty(&weatherTemp);
128+
weather.addProperty(&weatherPres);
129+
weather.addProperty(&weatherHum);
130+
adapter->addDevice(&weather);
131+
adapter->begin();
132+
}
133+
134+
void loop() {
135+
readBME280Data();
136+
adapter->update();
137+
}

examples/PlatformIO/LED/src/main.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* Simple server compliant with Mozilla's proposed WoT API
3+
* Originally based on the HelloServer example
4+
* Tested on ESP8266, ESP32, Arduino boards with WINC1500 modules (shields or
5+
* MKR1000)
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
10+
*/
11+
12+
#include <Arduino.h>
13+
#include "Thing.h"
14+
#include "WebThingAdapter.h"
15+
16+
// TODO: Hardcode your wifi credentials here (and keep it private)
17+
const char *ssid = "public";
18+
const char *password = "";
19+
20+
#if defined(LED_BUILTIN)
21+
const int ledPin = LED_BUILTIN;
22+
#else
23+
const int ledPin = 13; // manually configure LED pin
24+
#endif
25+
26+
WebThingAdapter *adapter;
27+
28+
const char *ledTypes[] = {"OnOffSwitch", "Light", nullptr};
29+
ThingDevice led("led", "Built-in LED", ledTypes);
30+
ThingProperty ledOn("on", "", BOOLEAN, "OnOffProperty");
31+
32+
bool lastOn = false;
33+
34+
void setup(void) {
35+
pinMode(ledPin, OUTPUT);
36+
digitalWrite(ledPin, HIGH);
37+
Serial.begin(115200);
38+
Serial.println("");
39+
Serial.print("Connecting to \"");
40+
Serial.print(ssid);
41+
Serial.println("\"");
42+
#if defined(ESP8266) || defined(ESP32)
43+
WiFi.mode(WIFI_STA);
44+
#endif
45+
WiFi.begin(ssid, password);
46+
Serial.println("");
47+
48+
// Wait for connection
49+
bool blink = true;
50+
while (WiFi.status() != WL_CONNECTED) {
51+
delay(500);
52+
Serial.print(".");
53+
digitalWrite(ledPin, blink ? LOW : HIGH); // active low led
54+
blink = !blink;
55+
}
56+
digitalWrite(ledPin, HIGH); // active low led
57+
58+
Serial.println("");
59+
Serial.print("Connected to ");
60+
Serial.println(ssid);
61+
Serial.print("IP address: ");
62+
Serial.println(WiFi.localIP());
63+
adapter = new WebThingAdapter("w25", WiFi.localIP());
64+
65+
led.addProperty(&ledOn);
66+
adapter->addDevice(&led);
67+
adapter->begin();
68+
Serial.println("HTTP server started");
69+
Serial.print("http://");
70+
Serial.print(WiFi.localIP());
71+
Serial.print("/things/");
72+
Serial.println(led.id);
73+
}
74+
75+
void loop(void) {
76+
adapter->update();
77+
bool on = ledOn.getValue().boolean;
78+
digitalWrite(ledPin, on ? LOW : HIGH); // active low led
79+
if (on != lastOn) {
80+
Serial.print(led.id);
81+
Serial.print(": ");
82+
Serial.println(on);
83+
}
84+
lastOn = on;
85+
}

examples/PlatformIO/LEDLamp/src/main.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)