Skip to content

Commit 00f79d5

Browse files
committed
initial support for Arduino R4 WiFi
1 parent 31c8ef2 commit 00f79d5

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#define THINGER_SERIAL_DEBUG
2+
3+
#include <ThingerR4WiFi.h>
4+
#include "arduino_secrets.h"
5+
6+
ThingerR4WiFi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
7+
8+
void setup() {
9+
// open serial for debugging
10+
Serial.begin(115200);
11+
12+
// configure wifi network
13+
thing.add_wifi(SSID, SSID_PASSWORD);
14+
15+
pinMode(LED_BUILTIN, OUTPUT);
16+
17+
// pin control example (i.e. turning on/off a light, a relay, etc)
18+
thing["led"] << digitalPin(LED_BUILTIN);
19+
20+
// resource output example (i.e. reading a sensor value, a variable, etc)
21+
thing["millis"] >> outputValue(millis());
22+
23+
// more details at http://docs.thinger.io/arduino/
24+
}
25+
26+
void loop() {
27+
thing.handle();
28+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#define USERNAME "your_user_name"
2+
#define DEVICE_ID "your_device_id"
3+
#define DEVICE_CREDENTIAL "your_device_credential"
4+
5+
#define SSID "your_wifi_ssid"
6+
#define SSID_PASSWORD "your_wifi_ssid_password"

src/ThingerR4WiFi.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2017 THINK BIG LABS SL
4+
// Author: alvarolb@gmail.com (Alvaro Luis Bustamante)
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
24+
#ifndef THINGER_R4WIFI_H
25+
#define THINGER_R4WIFI_H
26+
27+
#include <WiFiS3.h>
28+
#include "ThingerWifi.h"
29+
30+
// load SSL non-SSL client implementations
31+
#ifdef _DISABLE_TLS_
32+
#include <WiFiClient.h>
33+
typedef WiFiClient R4WiFiClient;
34+
#else
35+
#include <WiFiSSLClient.h>
36+
typedef WiFiSSLClient R4WiFiClient;
37+
#endif
38+
39+
class ThingerR4WiFi : public ThingerWifiClient<R4WiFiClient> {
40+
41+
public:
42+
ThingerR4WiFi(const char* user, const char* device, const char* device_credential) :
43+
ThingerWifiClient(user, device, device_credential)
44+
{
45+
46+
}
47+
48+
~ThingerR4WiFi(){
49+
50+
}
51+
52+
#ifndef _DISABLE_TLS_
53+
bool connect_socket() override{
54+
55+
#ifdef THINGER_INSECURE_SSL
56+
client_.setInsecure();
57+
THINGER_DEBUG("SSL/TLS", "Warning: TLS/SSL certificate will not be checked!")
58+
#else
59+
//client_.setTrustAnchors(&x509);
60+
#endif
61+
return client_.connect(get_host(), THINGER_SSL_PORT);
62+
}
63+
#endif
64+
65+
};
66+
67+
#endif

0 commit comments

Comments
 (0)