-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from hassfers/button_example
https example
- Loading branch information
Showing
11 changed files
with
1,354 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a | ||
# project subdirectory. | ||
# | ||
|
||
PROJECT_NAME := https-request | ||
|
||
include $(IDF_PATH)/make/project.mk | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Crossbar.io IoT ESP32 HTTPS - Call | ||
|
||
## Overview | ||
This example uses the ESP32 and FreeRTOS to remote call a procedure off the Crossbar demo instance using a HTTPS-call over WIFI | ||
|
||
## Important | ||
The ESP32 embedded TLS library doesn't contain any CA or Root certificates. | ||
You have to load the full CA-Chain you need into your program. | ||
In this example there are two needed. | ||
- [ISRGROOTX1](https://letsencrypt.org/certs/isrgrootx1.pem.txt) and | ||
- [Letsencryptauthorityx3](https://letsencrypt.org/certs/letsencryptauthorityx3.pem.txt) | ||
|
||
if these are outdated you can find fresh ones [here](https://letsencrypt.org/certificates/) | ||
|
||
after downloading the certificates you have to put them in one file in the given order. | ||
|
||
|
||
## What you need | ||
- a ESP-chip | ||
- the ESP-SKD (how to install following the instructions found [here](https://esp-idf.readthedocs.io/en/v1.0/)) | ||
|
||
|
||
|
||
## How to run | ||
### Set environment variables | ||
The first thing you have to do is set a few environment variables needed for WIFI connection | ||
so type in your terminal window | ||
```console | ||
export WIFI_SSID="YOUR WIFI SSID" | ||
export WIFI_KEY="YOUR WIFI PASSPHRASE" | ||
CROSSBAR_HTTP_BRIDGE=https://cbdemo-eu-central-1.crossbar.io:443 | ||
``` | ||
>alternatively you can set these variables in your ~/.profile file so you don't have to repeat this step every time you restart your bash | ||
> | ||
the value ```CROSSBAR_HTTP_BRIDGE``` will be parsed to protocol, host and port. | ||
### Build the ESP example | ||
|
||
after cloning the repo just jump in the downloaded folder and run | ||
|
||
```console | ||
make -j5 | ||
``` | ||
if your toolchain is installed right, it will build the whole project include the bootloader in a folder called "build" | ||
|
||
after building successful run | ||
```console | ||
make flash monitor | ||
``` | ||
this will download the project to your chip and run the serial monitor for debug output after finished flashing | ||
|
||
### Run the Program | ||
#### ESP32-Serial Monitor | ||
on your serial monitor you can see, after heaps of bootloader output, something like: | ||
```console | ||
I (372) example: Seeding the random number generator | ||
I (382) example: Loading the CA root certificate... | ||
I (392) example: Setting hostname for TLS session... | ||
I (392) example: Setting up the SSL/TLS structure... | ||
I (2222) example: Connected to AP | ||
I (2222) example: Connecting to cbdemo-eu-central-1.crossbar.io:443... | ||
I (2282) example: Connected. | ||
I (2282) example: Performing the SSL/TLS handshake... | ||
I (4642) example: Verifying peer X.509 certificate... | ||
I (4652) example: Certificate verified. | ||
I (4652) example: Writing HTTP request.. | ||
``` | ||
The important lines are the four above. If they look like this you have successful connected to the Crossbar Demo Instance over TLS and the communication is encrypted. | ||
```console | ||
REQUEST: POST /call HTTP/1.0 | ||
Host: cbdemo-eu-central-1.crossbar.io | ||
User-Agent: esp-idf/1.0 esp32 | ||
Accept: */* | ||
Content-Type: application/json | ||
Content-Length: 65 | ||
|
||
{"procedure":"com.example.split_name","args":["Maxi Mustermann"]} | ||
``` | ||
this is a complete print of the sended HTTP-Package. You can separate it in two parts: | ||
- Header (where all the connection informations are in) | ||
- Payload (the content you want to send. Here you have to put in which function of the Crossbar instance you want to call and what the parameters should be) | ||
|
||
In this example the same HTTP-Package is sended as in the HTTP example, but this time its sended over TSL, to the crossbar demo instance. This instance has no procedure called "com.example.split_name" and so we get the following output. | ||
|
||
```console | ||
HTTP/1.0 200 OK | ||
Server: Crossbar/17.5.1 | ||
Date: Mon, 31 Jul 2017 13:48:33 GMT | ||
Access-Control-Allow-Origin: * | ||
Access-Control-Allow-Credentials: true | ||
Cache-Control: no-store,no-cache,must-revalidate,max-age=0 | ||
Content-Type: application/json; charset=UTF-8 | ||
|
||
{"error": "wamp.error.no_such_procedure", "args": ["no callee registered for procedure <com.example.split_name>"], "kwargs": {}} | ||
``` | ||
If you get this answer, you know that everything with your connection works well and you only have to implement the wanted procedure at your crossbar instance. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw | ||
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh | ||
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4 | ||
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu | ||
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY | ||
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc | ||
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+ | ||
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U | ||
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+s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q4+63SM1N95R1NbdWhscdCb+ZAJzVc | ||
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq | ||
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA | ||
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d | ||
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
menu "Example Configuration" | ||
|
||
config WIFI_SSID | ||
string "WiFi SSID" | ||
default "myssid" | ||
help | ||
SSID (network name) for the example to connect to. | ||
|
||
config WIFI_PASSWORD | ||
string "WiFi Password" | ||
default "myssid" | ||
help | ||
WiFi password (WPA or WPA2) for the example to use. | ||
|
||
Can be left blank if the network has no security set. | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# Main component makefile. | ||
# | ||
# This Makefile can be left empty. By default, it will take the sources in the | ||
# src/ directory, compile them and link them into lib(subdirectory_name).a | ||
# in the build directory. This behaviour is entirely configurable, | ||
# please read the ESP-IDF documents if you need to do this. | ||
# | ||
COMPONENT_EMBED_TXTFILES :=isrgrootx1.pem | ||
CFLAGS += -DWIFI_SSID_VALUE=\"${WIFI_SSID}\" | ||
CFLAGS += -DWIFI_KEY_VALUE=\"${WIFI_KEY}\" | ||
CFLAGS += -DCROSSBAR_HTTP_BRIDGE_VALUE=\"${CROSSBAR_HTTP_BRIDGE}\" |
Oops, something went wrong.