Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 1360f17

Browse files
authored
v1.3.0
### Releases v1.3.0 1. Add support to **LAN8720** Ethernet for many **STM32F4** (F407xx, NUCLEO_F429ZI) and **STM32F7** (DISCO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG) boards. 2. Add LAN8720 examples 3. Add Packages' Patches for STM32 to use LAN8720 with STM32Ethernet and LwIP libraries
1 parent 37a32b5 commit 1360f17

26 files changed

+3255
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/****************************************************************************************************************************
2+
MQTTClient_SSL_Auth_LAN8720.ino - Dead simple SSL MQTT Client for Ethernet shields
3+
4+
For STM32F/L/H/G/WB/MP1 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
5+
6+
EthernetWebServer_SSL_STM32 is a library for STM32 using the Ethernet shields to run WebServer and Client with/without SSL
7+
8+
Use SSLClient Library code from https://github.com/OPEnSLab-OSU/SSLClient
9+
10+
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_SSL_STM32
11+
Licensed under MIT license
12+
*****************************************************************************************************************************/
13+
14+
/*
15+
Basic MQTT example (with SSL!) with Authentication
16+
This sketch demonstrates the basic capabilities of the library.
17+
It connects to an MQTT server then:
18+
- providing username and password
19+
- publishes "hello world" to the topic "outTopic"
20+
- subscribes to the topic "inTopic", printing out any messages
21+
it receives. NB - it assumes the received payloads are strings not binary
22+
It will reconnect to the server if the connection is lost using a blocking
23+
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
24+
achieve the same result without blocking the main loop.
25+
*/
26+
27+
#include "defines.h"
28+
29+
#include "certificates.h" // This file must be regenerated at https://openslab-osu.github.io/bearssl-certificate-utility/
30+
#include <PubSubClient.h>
31+
32+
const char my_cert[] = "FIXME";
33+
const char my_key[] = "FIXME";
34+
35+
SSLClientParameters mTLS = SSLClientParameters::fromPEM(my_cert, sizeof my_cert, my_key, sizeof my_key);
36+
37+
// Update these with values suitable for your network.
38+
//const char* mqttServer = "broker.example"; // Broker address
39+
const char* mqttServer = "broker.emqx.io"; // Broker address
40+
//IPAddress mqttServer(172, 16, 0, 2);
41+
42+
void callback(char* topic, byte* payload, unsigned int length)
43+
{
44+
Serial.print("Message arrived [");
45+
Serial.print(topic);
46+
Serial.print("] ");
47+
48+
for (unsigned int i = 0; i < length; i++)
49+
{
50+
Serial.print((char)payload[i]);
51+
}
52+
53+
Serial.println();
54+
}
55+
56+
EthernetClient ethClient;
57+
EthernetSSLClient ethClientSSL(ethClient, TAs, (size_t)TAs_NUM);
58+
59+
PubSubClient client(mqttServer, 8883, callback, ethClientSSL);
60+
61+
void reconnect()
62+
{
63+
// Loop until we're reconnected
64+
while (!client.connected())
65+
{
66+
Serial.print("Attempting MQTT connection...");
67+
68+
// Attempt to connect
69+
if (client.connect("arduinoClient", "testuser", "testpass"))
70+
{
71+
Serial.println("connected");
72+
// Once connected, publish an announcement...
73+
client.publish("outTopic", "hello world");
74+
// This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9
75+
ethClientSSL.flush();
76+
// ... and resubscribe
77+
client.subscribe("inTopic");
78+
// for loopback testing
79+
client.subscribe("outTopic");
80+
// This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9
81+
ethClientSSL.flush();
82+
}
83+
else
84+
{
85+
Serial.print("failed, rc=");
86+
Serial.print(client.state());
87+
Serial.println(" try again in 5 seconds");
88+
89+
// Wait 5 seconds before retrying
90+
delay(5000);
91+
}
92+
}
93+
}
94+
95+
void setup()
96+
{
97+
// Open serial communications and wait for port to open:
98+
Serial.begin(115200);
99+
delay(2000);
100+
101+
Serial.print("\nStart MQTTClient_SSL_Auth_LAN8720 on " + String(BOARD_NAME));
102+
Serial.println(" with " + String(SHIELD_TYPE));
103+
Serial.println(ETHERNET_WEBSERVER_SSL_STM32_VERSION);
104+
105+
// Enable mutual TLS with SSLClient
106+
ethClientSSL.setMutualAuthParams(mTLS);
107+
108+
// start the ethernet connection and the server:
109+
// Use DHCP dynamic IP and random mac
110+
uint16_t index = millis() % NUMBER_OF_MAC;
111+
// Use Static IP
112+
//Ethernet.begin(mac[index], ip);
113+
Ethernet.begin(mac[index]);
114+
115+
// you're connected now, so print out the data
116+
Serial.print(F("You're connected to the network, IP = "));
117+
Serial.println(Ethernet.localIP());
118+
119+
// Note - the default maximum packet size is 128 bytes. If the
120+
// combined length of clientId, username and password exceed this use the
121+
// following to increase the buffer size:
122+
// client.setBufferSize(255);
123+
}
124+
125+
void loop()
126+
{
127+
if (!client.connected())
128+
{
129+
reconnect();
130+
}
131+
132+
client.loop();
133+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#ifndef _CERTIFICATES_H_
2+
#define _CERTIFICATES_H_
3+
4+
#ifdef __cplusplus
5+
extern "C"
6+
{
7+
#endif
8+
9+
/* This file is auto-generated by the pycert_bearssl tool. Do not change it manually.
10+
* Certificates are BearSSL br_x509_trust_anchor format. Included certs:
11+
*
12+
* Index: 0
13+
* Label: AAA Certificate Services
14+
* Subject: CN=AAA Certificate Services,O=Comodo CA Limited,L=Salford,ST=Greater Manchester,C=GB
15+
* Domain(s): emqx.io
16+
*
17+
* Index: 1
18+
* Label: COMODO RSA Certification Authority
19+
* Subject: CN=COMODO RSA Certification Authority,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB
20+
* Domain(s): hivemq.com
21+
*/
22+
23+
#define TAs_NUM 2
24+
25+
static const unsigned char TA_DN0[] = {
26+
0x30, 0x7b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
27+
0x02, 0x47, 0x42, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x08,
28+
0x0c, 0x12, 0x47, 0x72, 0x65, 0x61, 0x74, 0x65, 0x72, 0x20, 0x4d, 0x61,
29+
0x6e, 0x63, 0x68, 0x65, 0x73, 0x74, 0x65, 0x72, 0x31, 0x10, 0x30, 0x0e,
30+
0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x61, 0x6c, 0x66, 0x6f,
31+
0x72, 0x64, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
32+
0x11, 0x43, 0x6f, 0x6d, 0x6f, 0x64, 0x6f, 0x20, 0x43, 0x41, 0x20, 0x4c,
33+
0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03,
34+
0x55, 0x04, 0x03, 0x0c, 0x18, 0x41, 0x41, 0x41, 0x20, 0x43, 0x65, 0x72,
35+
0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x53, 0x65, 0x72,
36+
0x76, 0x69, 0x63, 0x65, 0x73,
37+
};
38+
39+
static const unsigned char TA_RSA_N0[] = {
40+
0xbe, 0x40, 0x9d, 0xf4, 0x6e, 0xe1, 0xea, 0x76, 0x87, 0x1c, 0x4d, 0x45,
41+
0x44, 0x8e, 0xbe, 0x46, 0xc8, 0x83, 0x06, 0x9d, 0xc1, 0x2a, 0xfe, 0x18,
42+
0x1f, 0x8e, 0xe4, 0x02, 0xfa, 0xf3, 0xab, 0x5d, 0x50, 0x8a, 0x16, 0x31,
43+
0x0b, 0x9a, 0x06, 0xd0, 0xc5, 0x70, 0x22, 0xcd, 0x49, 0x2d, 0x54, 0x63,
44+
0xcc, 0xb6, 0x6e, 0x68, 0x46, 0x0b, 0x53, 0xea, 0xcb, 0x4c, 0x24, 0xc0,
45+
0xbc, 0x72, 0x4e, 0xea, 0xf1, 0x15, 0xae, 0xf4, 0x54, 0x9a, 0x12, 0x0a,
46+
0xc3, 0x7a, 0xb2, 0x33, 0x60, 0xe2, 0xda, 0x89, 0x55, 0xf3, 0x22, 0x58,
47+
0xf3, 0xde, 0xdc, 0xcf, 0xef, 0x83, 0x86, 0xa2, 0x8c, 0x94, 0x4f, 0x9f,
48+
0x68, 0xf2, 0x98, 0x90, 0x46, 0x84, 0x27, 0xc7, 0x76, 0xbf, 0xe3, 0xcc,
49+
0x35, 0x2c, 0x8b, 0x5e, 0x07, 0x64, 0x65, 0x82, 0xc0, 0x48, 0xb0, 0xa8,
50+
0x91, 0xf9, 0x61, 0x9f, 0x76, 0x20, 0x50, 0xa8, 0x91, 0xc7, 0x66, 0xb5,
51+
0xeb, 0x78, 0x62, 0x03, 0x56, 0xf0, 0x8a, 0x1a, 0x13, 0xea, 0x31, 0xa3,
52+
0x1e, 0xa0, 0x99, 0xfd, 0x38, 0xf6, 0xf6, 0x27, 0x32, 0x58, 0x6f, 0x07,
53+
0xf5, 0x6b, 0xb8, 0xfb, 0x14, 0x2b, 0xaf, 0xb7, 0xaa, 0xcc, 0xd6, 0x63,
54+
0x5f, 0x73, 0x8c, 0xda, 0x05, 0x99, 0xa8, 0x38, 0xa8, 0xcb, 0x17, 0x78,
55+
0x36, 0x51, 0xac, 0xe9, 0x9e, 0xf4, 0x78, 0x3a, 0x8d, 0xcf, 0x0f, 0xd9,
56+
0x42, 0xe2, 0x98, 0x0c, 0xab, 0x2f, 0x9f, 0x0e, 0x01, 0xde, 0xef, 0x9f,
57+
0x99, 0x49, 0xf1, 0x2d, 0xdf, 0xac, 0x74, 0x4d, 0x1b, 0x98, 0xb5, 0x47,
58+
0xc5, 0xe5, 0x29, 0xd1, 0xf9, 0x90, 0x18, 0xc7, 0x62, 0x9c, 0xbe, 0x83,
59+
0xc7, 0x26, 0x7b, 0x3e, 0x8a, 0x25, 0xc7, 0xc0, 0xdd, 0x9d, 0xe6, 0x35,
60+
0x68, 0x10, 0x20, 0x9d, 0x8f, 0xd8, 0xde, 0xd2, 0xc3, 0x84, 0x9c, 0x0d,
61+
0x5e, 0xe8, 0x2f, 0xc9,
62+
};
63+
64+
static const unsigned char TA_RSA_E0[] = {
65+
0x01, 0x00, 0x01,
66+
};
67+
68+
static const unsigned char TA_DN1[] = {
69+
0x30, 0x81, 0x85, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06,
70+
0x13, 0x02, 0x47, 0x42, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04,
71+
0x08, 0x13, 0x12, 0x47, 0x72, 0x65, 0x61, 0x74, 0x65, 0x72, 0x20, 0x4d,
72+
0x61, 0x6e, 0x63, 0x68, 0x65, 0x73, 0x74, 0x65, 0x72, 0x31, 0x10, 0x30,
73+
0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x07, 0x53, 0x61, 0x6c, 0x66,
74+
0x6f, 0x72, 0x64, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x0a,
75+
0x13, 0x11, 0x43, 0x4f, 0x4d, 0x4f, 0x44, 0x4f, 0x20, 0x43, 0x41, 0x20,
76+
0x4c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x31, 0x2b, 0x30, 0x29, 0x06,
77+
0x03, 0x55, 0x04, 0x03, 0x13, 0x22, 0x43, 0x4f, 0x4d, 0x4f, 0x44, 0x4f,
78+
0x20, 0x52, 0x53, 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69,
79+
0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f,
80+
0x72, 0x69, 0x74, 0x79,
81+
};
82+
83+
static const unsigned char TA_RSA_N1[] = {
84+
0x91, 0xe8, 0x54, 0x92, 0xd2, 0x0a, 0x56, 0xb1, 0xac, 0x0d, 0x24, 0xdd,
85+
0xc5, 0xcf, 0x44, 0x67, 0x74, 0x99, 0x2b, 0x37, 0xa3, 0x7d, 0x23, 0x70,
86+
0x00, 0x71, 0xbc, 0x53, 0xdf, 0xc4, 0xfa, 0x2a, 0x12, 0x8f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xcc, 0x81, 0x48, 0x43, 0x67, 0x4e, 0x72, 0x2a,
102+
0x9b, 0x5c, 0xbd, 0x4c, 0x1b, 0x28, 0x8a, 0x5c, 0x22, 0x7b, 0xb4, 0xab,
103+
0x98, 0xd9, 0xee, 0xe0, 0x51, 0x83, 0xc3, 0x09, 0x46, 0x4e, 0x6d, 0x3e,
104+
0x99, 0xfa, 0x95, 0x17, 0xda, 0x7c, 0x33, 0x57, 0x41, 0x3c, 0x8d, 0x51,
105+
0xed, 0x0b, 0xb6, 0x5c, 0xaf, 0x2c, 0x63, 0x1a, 0xdf, 0x57, 0xc8, 0x3f,
106+
0xbc, 0xe9, 0x5d, 0xc4, 0x9b, 0xaf, 0x45, 0x99, 0xe2, 0xa3, 0x5a, 0x24,
107+
0xb4, 0xba, 0xa9, 0x56, 0x3d, 0xcf, 0x6f, 0xaa, 0xff, 0x49, 0x58, 0xbe,
108+
0xf0, 0xa8, 0xff, 0xf4, 0xb8, 0xad, 0xe9, 0x37, 0xfb, 0xba, 0xb8, 0xf4,
109+
0x0b, 0x3a, 0xf9, 0xe8, 0x43, 0x42, 0x1e, 0x89, 0xd8, 0x84, 0xcb, 0x13,
110+
0xf1, 0xd9, 0xbb, 0xe1, 0x89, 0x60, 0xb8, 0x8c, 0x28, 0x56, 0xac, 0x14,
111+
0x1d, 0x9c, 0x0a, 0xe7, 0x71, 0xeb, 0xcf, 0x0e, 0xdd, 0x3d, 0xa9, 0x96,
112+
0xa1, 0x48, 0xbd, 0x3c, 0xf7, 0xaf, 0xb5, 0x0d, 0x22, 0x4c, 0xc0, 0x11,
113+
0x81, 0xec, 0x56, 0x3b, 0xf6, 0xd3, 0xa2, 0xe2, 0x5b, 0xb7, 0xb2, 0x04,
114+
0x22, 0x52, 0x95, 0x80, 0x93, 0x69, 0xe8, 0x8e, 0x4c, 0x65, 0xf1, 0x91,
115+
0x03, 0x2d, 0x70, 0x74, 0x02, 0xea, 0x8b, 0x67, 0x15, 0x29, 0x69, 0x52,
116+
0x02, 0xbb, 0xd7, 0xdf, 0x50, 0x6a, 0x55, 0x46, 0xbf, 0xa0, 0xa3, 0x28,
117+
0x61, 0x7f, 0x70, 0xd0, 0xc3, 0xa2, 0xaa, 0x2c, 0x21, 0xaa, 0x47, 0xce,
118+
0x28, 0x9c, 0x06, 0x45, 0x76, 0xbf, 0x82, 0x18, 0x27, 0xb4, 0xd5, 0xae,
119+
0xb4, 0xcb, 0x50, 0xe6, 0x6b, 0xf4, 0x4c, 0x86, 0x71, 0x30, 0xe9, 0xa6,
120+
0xdf, 0x16, 0x86, 0xe0, 0xd8, 0xff, 0x40, 0xdd, 0xfb, 0xd0, 0x42, 0x88,
121+
0x7f, 0xa3, 0x33, 0x3a, 0x2e, 0x5c, 0x1e, 0x41, 0x11, 0x81, 0x63, 0xce,
122+
0x18, 0x71, 0x6b, 0x2b, 0xec, 0xa6, 0x8a, 0xb7, 0x31, 0x5c, 0x3a, 0x6a,
123+
0x47, 0xe0, 0xc3, 0x79, 0x59, 0xd6, 0x20, 0x1a, 0xaf, 0xf2, 0x6a, 0x98,
124+
0xaa, 0x72, 0xbc, 0x57, 0x4a, 0xd2, 0x4b, 0x9d, 0xbb, 0x10, 0xfc, 0xb0,
125+
0x4c, 0x41, 0xe5, 0xed, 0x1d, 0x3d, 0x5e, 0x28, 0x9d, 0x9c, 0xcc, 0xbf,
126+
0xb3, 0x51, 0xda, 0xa7, 0x47, 0xe5, 0x84, 0x53,
127+
};
128+
129+
static const unsigned char TA_RSA_E1[] = {
130+
0x01, 0x00, 0x01,
131+
};
132+
133+
static const br_x509_trust_anchor TAs[] = {
134+
{
135+
{ (unsigned char *)TA_DN0, sizeof TA_DN0 },
136+
BR_X509_TA_CA,
137+
{
138+
BR_KEYTYPE_RSA,
139+
{ .rsa = {
140+
(unsigned char *)TA_RSA_N0, sizeof TA_RSA_N0,
141+
(unsigned char *)TA_RSA_E0, sizeof TA_RSA_E0,
142+
} }
143+
}
144+
},
145+
{
146+
{ (unsigned char *)TA_DN1, sizeof TA_DN1 },
147+
BR_X509_TA_CA,
148+
{
149+
BR_KEYTYPE_RSA,
150+
{ .rsa = {
151+
(unsigned char *)TA_RSA_N1, sizeof TA_RSA_N1,
152+
(unsigned char *)TA_RSA_E1, sizeof TA_RSA_E1,
153+
} }
154+
}
155+
},
156+
};
157+
158+
#ifdef __cplusplus
159+
} /* extern "C" */
160+
#endif
161+
162+
#endif /* ifndef _CERTIFICATES_H_ */

0 commit comments

Comments
 (0)