Skip to content

Commit e6f3df4

Browse files
committed
* Default SSL enabled for ESP8266 and Arduino! (can be disabled using #defines)
* Improved debug info to detect if the device is connecting trhough secure connections. * Added support for call other devices directly from code without calling endpoints! * Improved call_endpoint data to actually output the resource data. * Added support to specify different server parameters, like hosts, or ports, to start supporting local deployments. * Some minor changes in binary messages to properly support calling devices, or endpoints.
1 parent 55ad3d8 commit e6f3df4

File tree

15 files changed

+238
-39
lines changed

15 files changed

+238
-39
lines changed

examples/ArduinoWifi/ArduinoWifi.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define SSID "your_wifi_ssid"
1010
#define SSID_PASSWORD "your_wifi_ssid_password"
1111

12-
ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
12+
ThingerWifi<> thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
1313

1414
void setup() {
1515
// configure wifi network

examples/ESP8266/ESP8266.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <ESP8266WiFi.h>
2-
#include <ThingerWifi.h>
2+
#include <ThingerESP8266.h>
33

44
#define USERNAME "your_user_name"
55
#define DEVICE_ID "your_device_id"
@@ -8,7 +8,7 @@
88
#define SSID "your_wifi_ssid"
99
#define SSID_PASSWORD "your_wifi_ssid_password"
1010

11-
ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
11+
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
1212

1313
void setup() {
1414
pinMode(BUILTIN_LED, OUTPUT);

examples/EnergiaCC3200/EnergiaCC3200.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define SSID "your_wifi_ssid"
99
#define SSID_PASSWORD "your_wifi_ssid_password"
1010

11-
ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
11+
ThingerWifi<> thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
1212

1313
void setup() {
1414
// set the boards led to output

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=thinger.io
2-
version=2.4.3
2+
version=2.5.0
33
author=Alvaro Luis Bustamante <[email protected]>
44
maintainer=Thinger.io <[email protected]>
55
sentence=Arduino library for the Thinger.io Internet of Things Platform.

src/ThingerClient.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,28 @@ dynamic_memory_allocator alloc;
3232
//circular_memory_allocator<512> alloc;
3333
memory_allocator& protoson::pool = alloc;
3434

35-
#define THINGER_SERVER "iot.thinger.io"
36-
#define THINGER_PORT 25200
37-
#define THINGER_SSL_PORT 25202
38-
#define RECONNECTION_TIMEOUT 5000 // milliseconds
39-
#define DEFAULT_READ_TIMEOUT 30000
35+
#ifndef THINGER_SERVER
36+
#define THINGER_SERVER "iot.thinger.io"
37+
#endif
38+
39+
#ifndef THINGER_PORT
40+
#define THINGER_PORT 25200
41+
#endif
42+
43+
#ifndef THINGER_SSL_PORT
44+
#define THINGER_SSL_PORT 25202
45+
#endif
46+
47+
#ifndef THINGER_TLS_FINGERPRINT
48+
#define THINGER_TLS_FINGERPRINT "50 1E ED 5D F3 E1 94 EC 2D 43 1E 22 4E 1D 5E 8B EB 66 8D EA"
49+
#endif
50+
51+
#ifndef THINGER_TLS_HOST
52+
#define THINGER_TLS_HOST "thinger.io"
53+
#endif
54+
55+
#define RECONNECTION_TIMEOUT 5000 // milliseconds
56+
#define DEFAULT_READ_TIMEOUT 30000 // milliseconds
4057

4158
#ifdef _DEBUG_
4259
#define THINGER_DEBUG(type, text) Serial.print("["); Serial.print(F(type)); Serial.print("] "); Serial.println(F(text));
@@ -139,6 +156,10 @@ class ThingerClient : public thinger::thinger {
139156
return client_.connect(THINGER_SERVER, THINGER_PORT);
140157
}
141158

159+
virtual bool secure_connection(){
160+
return false;
161+
}
162+
142163
enum THINGER_STATE{
143164
NETWORK_CONNECTING,
144165
NETWORK_CONNECTED,
@@ -169,8 +190,10 @@ class ThingerClient : public thinger::thinger {
169190
Serial.print(F("[_SOCKET] Connecting to "));
170191
Serial.print(THINGER_SERVER);
171192
Serial.print(F(":"));
172-
Serial.print(THINGER_PORT);
193+
Serial.print(secure_connection() ? THINGER_SSL_PORT : THINGER_PORT);
173194
Serial.println(F("..."));
195+
Serial.print(F("[_SOCKET] Using secure TLS/SSL connection: "));
196+
Serial.println(secure_connection() ? F("yes") : F("no"));
174197
break;
175198
case SOCKET_CONNECTED:
176199
THINGER_DEBUG("_SOCKET", "Connected!");

src/ThingerESP8266.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2016 THINK BIG LABS SL
4+
// Author: [email protected] (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_ESP8266_H
25+
#define THINGER_ESP8266_H
26+
27+
#include "ThingerWifi.h"
28+
29+
#ifndef _DISABLE_TLS_
30+
class ThingerESP8266 : public ThingerWifi<WiFiClientSecure>{
31+
#else
32+
class ThingerESP8266 : public ThingerWifi<>{
33+
#endif
34+
35+
public:
36+
ThingerESP8266(const char* user, const char* device, const char* device_credential) :
37+
ThingerWifi(user, device, device_credential)
38+
{}
39+
40+
~ThingerESP8266(){
41+
42+
}
43+
44+
#ifndef _DISABLE_TLS_
45+
protected:
46+
virtual bool connect_socket(){
47+
if(client_.connect(THINGER_SERVER, THINGER_SSL_PORT)){
48+
if(client_.verify(THINGER_TLS_FINGERPRINT, THINGER_TLS_HOST)){
49+
#ifdef _DEBUG_
50+
THINGER_DEBUG("_SOCKET", "SSL/TLS Host Verification Succeed!");
51+
#endif
52+
}else{
53+
#ifdef _DEBUG_
54+
THINGER_DEBUG("_SOCKET", "SSL/TLS Host Verification Error!");
55+
#endif
56+
}
57+
return true;
58+
}
59+
return false;
60+
}
61+
62+
virtual bool secure_connection(){
63+
return true;
64+
}
65+
#endif
66+
67+
};
68+
69+
#endif

src/ThingerSmartConfig.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,22 @@ class ThingerSmartConfig : public ThingerClient {
126126
return true;
127127
}
128128

129+
#ifndef _DISABLE_TLS_
130+
virtual bool connect_socket(){
131+
return client_.connect(THINGER_SERVER, THINGER_SSL_PORT) && client_.verify(THINGER_TLS_FINGERPRINT, THINGER_TLS_HOST);
132+
}
133+
virtual bool secure_connection(){
134+
return true;
135+
}
136+
#endif
137+
129138
private:
130139
bool use_led_;
140+
#ifndef _DISABLE_TLS_
141+
WiFiClientSecure client_;
142+
#else
131143
WiFiClient client_;
144+
#endif
132145
};
133146

134147
#endif

src/ThingerWebConfig.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,21 @@ class ThingerWebConfig : public ThingerClient {
192192
return true;
193193
}
194194

195+
#ifndef _DISABLE_TLS_
196+
virtual bool connect_socket(){
197+
return client_.connect(THINGER_SERVER, THINGER_SSL_PORT) && client_.verify(THINGER_TLS_FINGERPRINT, THINGER_TLS_HOST);
198+
}
199+
virtual bool secure_connection(){
200+
return true;
201+
}
202+
#endif
203+
195204
private:
205+
#ifndef _DISABLE_TLS_
206+
WiFiClientSecure client_;
207+
#else
196208
WiFiClient client_;
209+
#endif
197210
char user[40];
198211
char device[40];
199212
char device_credential[40];

src/ThingerWifi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "ThingerClient.h"
2828

29+
template <class Client = WiFiClient>
2930
class ThingerWifi : public ThingerClient {
3031

3132
public:
@@ -75,8 +76,7 @@ class ThingerWifi : public ThingerClient {
7576
}
7677

7778
protected:
78-
79-
WiFiClient client_;
79+
Client client_;
8080
const char* wifi_ssid_;
8181
const char* wifi_password_;
8282
};

src/ThingerWifi101.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,27 @@
2626

2727
#include "ThingerWifi.h"
2828

29-
class ThingerWifi101 : public ThingerWifi {
29+
class ThingerWifi101 : public ThingerWifi<> {
3030

3131
public:
32-
ThingerWifi101(const char* user, const char* device, const char* device_credential, bool ssl = true) :
33-
ThingerWifi(user, device, device_credential), ssl_(ssl)
32+
ThingerWifi101(const char* user, const char* device, const char* device_credential) :
33+
ThingerWifi(user, device, device_credential)
3434
{}
3535

3636
~ThingerWifi101(){
3737

3838
}
3939

40+
#ifndef _DISABLE_TLS_
4041
protected:
41-
4242
virtual bool connect_socket(){
43-
if(ssl_){
44-
return client_.connectSSL(THINGER_SERVER, THINGER_SSL_PORT);
45-
}else{
46-
return client_.connect(THINGER_SERVER, THINGER_PORT);
47-
}
43+
return client_.connectSSL(THINGER_SERVER, THINGER_SSL_PORT);
44+
}
45+
virtual bool secure_connection(){
46+
return true;
4847
}
48+
#endif
4949

50-
private:
51-
bool ssl_;
5250
};
5351

5452
#endif

0 commit comments

Comments
 (0)