|
| 1 | +#include <Arduino_RouterBridge.h> |
| 2 | + |
| 3 | +static const char ca_cert[] = { |
| 4 | +"-----BEGIN CERTIFICATE-----\n" |
| 5 | +"MIICCTCCAY6gAwIBAgINAgPlwGjvYxqccpBQUjAKBggqhkjOPQQDAzBHMQswCQYD\n" |
| 6 | +"VQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEUMBIG\n" |
| 7 | +"A1UEAxMLR1RTIFJvb3QgUjQwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAwMDAw\n" |
| 8 | +"WjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2Vz\n" |
| 9 | +"IExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjQwdjAQBgcqhkjOPQIBBgUrgQQAIgNi\n" |
| 10 | +"AATzdHOnaItgrkO4NcWBMHtLSZ37wWHO5t5GvWvVYRg1rkDdc/eJkTBa6zzuhXyi\n" |
| 11 | +"QHY7qca4R9gq55KRanPpsXI5nymfopjTX15YhmUPoYRlBtHci8nHc8iMai/lxKvR\n" |
| 12 | +"HYqjQjBAMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQW\n" |
| 13 | +"BBSATNbrdP9JNqPV2Py1PsVq8JQdjDAKBggqhkjOPQQDAwNpADBmAjEA6ED/g94D\n" |
| 14 | +"9J+uHXqnLrmvT/aDHQ4thQEd0dlq7A/Cr8deVl5c1RxYIigL9zC2L7F8AjEA8GE8\n" |
| 15 | +"p/SgguMh1YQdc4acLa/KNJvxn7kjNuK8YAOdgLOaVsjh4rsUecrNIdSUtUlD\n" |
| 16 | +"-----END CERTIFICATE-----\n" |
| 17 | +}; |
| 18 | + |
| 19 | +BridgeTCPClient<> client(Bridge); |
| 20 | + |
| 21 | +void setup() { |
| 22 | + |
| 23 | + if (!Bridge.begin()) { |
| 24 | + while (true) {} |
| 25 | + } |
| 26 | + |
| 27 | + if (!Monitor.begin()) { |
| 28 | + while (true) {} |
| 29 | + } |
| 30 | + |
| 31 | +} |
| 32 | + |
| 33 | +void loop() { |
| 34 | + Monitor.println("\nStarting connection to server..."); |
| 35 | + |
| 36 | + /* if you get a connection, report back via monitor: */ |
| 37 | + if (client.connectSSL("arduino.tips", 443, ca_cert) < 0) { |
| 38 | + Monitor.println("unable to connect to server"); |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + Monitor.println("connected to server"); |
| 43 | + /* Make aHTTP request: */ |
| 44 | + size_t w = client.println("GET /asciilogo.txt HTTP/1.1"); |
| 45 | + w += client.println("Host: arduino.tips"); |
| 46 | + w += client.println("User-Agent: Arduino"); |
| 47 | + w += client.println("Connection: close"); |
| 48 | + w += client.println(); |
| 49 | + |
| 50 | + /* if there are incoming bytes available from the server, |
| 51 | + * read them and print them: |
| 52 | + */ |
| 53 | + while (client.connected()) { |
| 54 | + size_t len = client.available(); |
| 55 | + if (len) { |
| 56 | + uint8_t buff[len]; |
| 57 | + client.read(buff, len); |
| 58 | + Monitor.write(buff, len); |
| 59 | + } |
| 60 | + delay(0); |
| 61 | + } |
| 62 | + |
| 63 | + /* if the server's disconnected, stop the client: */ |
| 64 | + Monitor.println(); |
| 65 | + Monitor.println("disconnecting from server."); |
| 66 | + client.stop(); |
| 67 | + delay(1000); |
| 68 | +} |
0 commit comments