README.md 7.7 KB
Newer Older
C
Carsten Gregersen 已提交
1 2
# uNabto ESP32 cam demo

W
wm 已提交
3 4
Using Nabto's SDK, the smartConfig network function has been added. Thanks to Nabto's technical support, I solved the problem of network delay.

C
Carsten Gregersen 已提交
5 6 7 8 9 10
This project turns the ESP32-CAM into a remote P2P accesible surveillance camera.
It uses the esp-idf FreeRTOS based core (vs. some other demos which uses the arduino core).
Also it uses the espressif esp32-cam library with slight modification (we could not get the reset to work).

The video is MJPEG and the module can cope to remotely stream (encode to mjpeg and encrypt and integrity check) a VGA feed at around 10 frames per second.

C
crgregersen 已提交
11 12 13
You should also read the related blog article:
https://www.nabto.com/esp32/

C
Carsten Gregersen 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
# The structure

The structure of the project is as follows
<pre>

    +
    +-->+-------------+
    |   |    Main     |        This folder contains the initial setup
    |   +-------------+        and the application_event() function defining
    |                          the application
    +-->+-------------+
        |  Components |
        +-------------+
                      |
                      +------->+----------------+
                      |        | unabto         |    Don't edit here (link to other github rep)
                      |        +----------------+
                      |
                      +------->+----------------+
                      |        | unabto-esp-idf |    The platform integration
                      |        +----------------+
                      |
                      +------->+----------------+
                      |        | nabtotunnel    |    Nabto tunnel application
                      |        +----------------+
                      |
                      +------->+----------------+
                      |        | unabto-esp-    |    Client fingerprint database
                      |        | fingerprint    |    storage in NVS
                      |        +----------------+
                      |
                      +------->+----------------+
                               | esp32-camera   |    From the espressif github (not a link, since we adjusted)
                               +----------------+
</pre>


ESP-IDF project has a speciel structure. You can read more about that here:
https://esp-idf.readthedocs.io/en/v1.0/build_system.html
The unabto source and the integration code is done as components and therefore resides in the IDF component folder.
The unabto sdk is a submodule link to the unabto generic source.

The initial setup/commisioning and the application is located in the main folder.
unabto_application.c contains the application (inside the application_event function), the main.c contains the setup and configuration of the WiFi module.


# How to set it up

## Step 1: Setup the ESP-IDF build environment

Follow the setup of the ESP-IDF toolchain setup

C
crgregersen 已提交
66 67
http://esp-idf.readthedocs.io/en/stable/get-started/index.html
(WARNING!!! It is important to use the "stable" release not latests.. Issues with fcntl has been detected as of late june 2019)
C
Carsten Gregersen 已提交
68 69 70 71 72

## Step 2: Clone the repository


```
A
AI-Thinker-wm 已提交
73
git clone --recursive https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_ESP32-CAMERA_WAN.git
C
Carsten Gregersen 已提交
74 75 76 77
```

## Step 3: Make menuconfig

N
Nabto ApS 已提交
78
Enter into menu "Camera configuration"
C
Carsten Gregersen 已提交
79 80 81 82 83 84 85 86 87

Edit/adjust the following menu items:


* WIFI access point name (SSID) : The wifi access point you want the module to attach to
* WIFI password : The password used by the access point
* Nabto ID : The Nabto device id you get from your AppMyProduct account
* Nabto key - 32 hex chars : The key for the specific device id you entered in the before mentioned item

N
Nabto ApS 已提交
88 89
Camera wiring! If you have an ESP-EYE board nothing else needs to be set up if you have an “ESP32 Cam” from Ai Tinker you need to configure this too (also in the “Camera configuration” menu).

C
Carsten Gregersen 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

## Step 3: Build the project

```
make
```

## Step 4: Flash the Image

Possible you need to adjust the serial deivce to use for flashing which is setup in the menuconfig part, but mostly the standard setup will match your platform.

```
make flash
```


# How to test the application


## Monitor the output from the board

Using the monitor command you should see a printout similar to the following every time the ESP32-EVB starts up:

N
Nabto ApS 已提交
113
Look for the "connected!" telling that the device knows how to connect to your WIFI. Also look for the Nabto state change to "ATTACHED" meaning that the device succesfully attached to Nabto infrastructure (registered and is online, waiting for connect requests from clients). The cloud service (controller) address can be varying dependent on geographic region (we have 4 datacenters) and availabillity.
C
Carsten Gregersen 已提交
114 115

```
N
Nabto ApS 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
00:00:01:457 main.c(382) connected!
00:00:01:460 main.c(388) IP Address:  192.168.2.147
00:00:01:465 main.c(389) Subnet mask: 255.255.255.0
00:00:01:470 main.c(390) Gateway:     192.168.2.1
00:00:01:475 unabto_application.c(59) In demo_init
00:00:01:479 unabto_application.c(78) Before fp_mem_init
00:00:01:495 unabto_application.c(81) Before acl_ae_init
00:00:01:495 unabto_common_main.c(110) Device id: 'jicnkjqs.ev9dbf.appmyproduct.com'
00:00:01:498 unabto_common_main.c(111) Program Release 4.4.0-alpha.0
00:00:01:505 network_adapter.c(140) Socket opened: port=5570
00:00:01:510 network_adapter.c(140) Socket opened: port=49153
00:00:01:515 unabto_stream_event.c(235) sizeof(stream__)=328
00:00:01:521 unabto_context.c(55) SECURE ATTACH: 1, DATA: 1
00:00:01:526 unabto_context.c(63) NONCE_SIZE: 32, CLEAR_TEXT: 0
00:00:01:532 unabto_common_main.c(183) Nabto was successfully initialized
00:00:01:539 unabto_context.c(55) SECURE ATTACH: 1, DATA: 1
00:00:01:543 unabto_context.c(63) NONCE_SIZE: 32, CLEAR_TEXT: 0
00:00:01:550 network_adapter.c(140) Socket opened: port=49154
00:00:01:555 unabto_attach.c(770) State change from IDLE to WAIT_DNS
00:00:01:561 unabto_attach.c(771) Resolving DNS for jicnkjqs.ev9dbf.appmyproduct.com
00:00:01:675 unabto_attach.c(790) Resolved DNS for jicnkjqs.ev9dbf.appmyproduct.com to:
00:00:01:675 unabto_attach.c(796)   Controller ip: 34.232.129.33
00:00:01:678 unabto_attach.c(802) State change from WAIT_DNS to WAIT_BS
00:00:01:887 unabto_attach.c(480) State change from WAIT_BS to WAIT_GSP
00:00:01:888 unabto_attach.c(481) GSP address: 34.194.195.231:5565
00:00:01:895 unabto_attach.c(270) ########    U_INVITE with LARGE nonce sent, version: - URL: -
00:00:02:089 unabto_attach.c(563) State change from WAIT_GSP to ATTACHED
C
Carsten Gregersen 已提交
143 144
```

N
Nabto ApS 已提交
145 146 147
To test the camera you can try to access:
http://<adress of camera>:8081/

N
Nabto ApS 已提交
148 149 150 151 152
Which will show something like this:

<p align="center">
<img border="1" src="docs/ESP-EYE-browser.png">
</p>
N
Nabto ApS 已提交
153 154


C
Carsten Gregersen 已提交
155 156 157
## Download the AMP video app

Download the Android or iPhone app from app store
N
Nabto ApS 已提交
158 159
* https://play.google.com/store/apps/details?id=com.appmyproduct.video
* https://itunes.apple.com/lc/app/appmyproduct-video-client/id1276975254
C
Carsten Gregersen 已提交
160 161 162

## Pair the video app with the wifi module

N
Nabto ApS 已提交
163
Setup your phone to be connected to the same WIFI network as the device. This is ultra important since the app and the device will do a broadcast discovery to find eachother. The app will create an anonomous PKI cert and send the fingerprint of the key (like SSH) to the device on the local network which is considered "safe" (ie. don't pair on public network). The device add this fingerprint to the access control list and after this the device will now accept that the app can remotely connect. Read more about [Nabto access control lists and pairing here](https://www.nabto.com/pairing-and-access-control-part-1-intro-and-device/).
N
Nabto ApS 已提交
164

N
Nabto ApS 已提交
165 166 167 168 169

<p align="center">
<img border="1" src="docs/esp32cam-overview.png">
<img border="1" src="docs/esp32cam-discover.png">
</p>
C
Carsten Gregersen 已提交
170 171

## Connect and view video
N
Nabto ApS 已提交
172 173 174 175 176 177 178 179

Now you should be able to connect to the camera when you click on the camera logo.

<p align="center">
<img border="1" src="docs/esp32cam-overviewpaired.png">
<img border="1" src="docs/esp32cam-viewcamera.png">
</p>