Compare commits

...

100 Commits

Author SHA1 Message Date
d011dd7ef5 Missing include in BLE header causes compilation to fail (#3865) 2020-09-30 15:00:22 +03:00
475208e535 IDF release/v4.0 48ea44f3d 2020-07-18 18:14:30 +00:00
2bf655b658 IDF release/v4.0 94d97499a 2020-06-17 12:13:29 +00:00
2fbbae762b IDF release/v4.0 e7ac221b4 2020-06-16 00:23:34 +00:00
d2761a9eab IDF release/v4.0 4c81978a3 2020-05-21 06:09:30 +00:00
8c8d8610f4 IDF release/v4.0 b0f053d82 2020-05-08 12:08:46 +00:00
c2da05050e IDF release/v4.0 fe67bedee 2020-04-16 06:09:39 +00:00
3746ef9df9 IDF release/v4.0 6825d8e0b 2020-04-14 00:14:38 +00:00
92eb1a2264 IDF release/v4.0 acdba0eb4 2020-04-13 12:10:06 +00:00
b47b0dc966 IDF release/v4.0 a3f3c7bdc 2020-04-07 00:12:32 +00:00
2271c7726d Merge branch 'idf-release/v4.0' of https://github.com/espressif/arduino-esp32 into idf-release/v4.0 2020-04-07 01:26:44 +03:00
9afee31462 Fix ETH in 4.0 2020-04-07 01:26:36 +03:00
f15a6ac205 Fix 3.3 compatibility 2020-04-07 01:11:14 +03:00
176077b133 IDF release/v4.0 b6bec84c6 2020-02-13 18:10:22 +00:00
60f20a7869 IDF release/v4.0 230931310 2020-02-13 00:13:59 +00:00
8817e536fd IDF release/v4.0 a61fd1e42 2020-01-29 12:08:12 +00:00
d1e3122d87 Merge branch 'idf-4.0-prep' of https://github.com/espressif/arduino-esp32 into idf-release/v4.0 2020-01-27 18:03:49 +02:00
856e596c79 Pass ethernet events to the main handler 2020-01-27 18:03:03 +02:00
2a88f72c4e Merge branch 'idf-4.0-prep' of https://github.com/espressif/arduino-esp32 into idf-release/v4.0 2020-01-27 17:34:48 +02:00
354e485c4b get smart config to work as well 2020-01-27 17:34:30 +02:00
5d9a22eb3a Merge branch 'idf-4.0-prep' of https://github.com/espressif/arduino-esp32 into idf-release/v4.0 2020-01-27 16:45:02 +02:00
1c4966566c make ETH work 2020-01-27 16:22:07 +02:00
4bb60f68da Update package_esp32_index.template.json 2020-01-27 13:50:33 +02:00
a9fa894f0d Merge branch 'idf-4.0-prep' of https://github.com/espressif/arduino-esp32 into idf-release/v4.0 2020-01-25 22:41:53 +02:00
251d5ef92b Update CMakeLists.txt 2020-01-25 22:41:03 +02:00
41ba143063 IDF release/v4.0 08219f3cf 2020-01-25 14:51:58 +00:00
8c723be135 Initial IDF-4.0 port
SmartConfig and ETH need some work to adapt to the new API
2020-01-25 16:24:19 +02:00
b50a1755c8 Use python3 in CI 2020-01-25 15:26:16 +02:00
bb0a194bb7 fix WiFiClient.connected() (#3654)
WiFiClient.connected() was hanging thinking there was still a connection when the remote had already closed. The one-liner in this patch addresses recv() returning 0 and errno==128. I couldn't find the corresponding errno for 128 but its caught by the case statement which includes EPIPE, ENOTCONN, ECONNRESET and ECONNABORTED so I assume its one of those. Broken pipe maybe?
```c
[D][WiFiClient.cpp:511] connected(): Disconnected: RES: 0, ERR: 128
```
EDIT: added comment to reflect that recv() can set errno when it returns 0.
2020-01-21 12:36:03 +02:00
ed59ae6482 Update README.md (#3653) 2020-01-21 12:35:05 +02:00
b4a9684a74 Fix SerialBT.flush (#3579)
* Fix flush

flush should not flush the read buffer, it should wait till all output is drained from the write buffer.

* Update BluetoothSerial.cpp

Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
2020-01-20 22:34:57 +02:00
1977370e6f IDF release/v3.3 (#3339)
* IDF release/v3.3 46b12a560

* fix build

* IDF release/v3.3 367c3c09c
2020-01-20 22:07:04 +02:00
307b1368dd Implement BTSerial onData to dynamically receive packets from SPP (#3649) 2020-01-20 19:43:52 +02:00
32d5654aa6 Implement rmtLoop to be able to continuously send pulses (#3650)
Number of pulses is limited to the reserved RMT memory for the channel. Very useful for PWM, Servo and other repeatable signals.
2020-01-20 19:43:13 +02:00
7637a739cc Fix recent commit d8b2098 (PR #3377) which includes esp_adc_cal component but does not update CMakeLists.txt (#3648) 2020-01-20 18:40:40 +02:00
cd85239252 Added file.close to examples (#3611) 2020-01-20 16:47:40 +02:00
ac9d04a400 Add BLEDevice::stopAdvertising() helper method to compliment startAdvertising(). (#3624) 2020-01-20 16:31:12 +02:00
2195109ecc Added the channel parameter to the scan fucntion in order to select which channel to scan. (#3638)
The default value is 0 (= all channels) to preserve backward compatibility.
2020-01-20 16:13:10 +02:00
8d938c849d Add HONEYLemon board (#3640)
* add board HONEYLemon
2020-01-20 16:12:02 +02:00
cb005fc8b5 Extend BLEDevice::setPower() to include powerType parameter. It's optional and set to ESP_BLE_PWR_TYPE_DEFAULT for compatibility. (#3623)
Extend BLEDevice::setPower() to include powerType parameter. It's optional and set to ESP_BLE_PWR_TYPE_DEFAULT for compatibility.
2020-01-20 16:09:02 +02:00
89351e3ade Update WiFiClient.cpp (#3608)
fixed the connected() function so that it only checks errno if recv returns a value of -1.

"in the even of an error, errno is set to indicate the error" --manpage

This fixes the ESP32 Webserver when dealing with a modern webserver with a slow SD card.
2020-01-20 16:08:17 +02:00
86de90fe24 Added partition and flash size menus for VintLabs boards (#3602)
add the partition and flash size menus for the VintLabs board definitions.
2020-01-20 16:07:53 +02:00
5960cd3e2a update coreESP32 boards.txt (#3569) 2020-01-20 16:06:55 +02:00
82e208c8c9 Fixed incorrect board name for TinyPICO - You can now use this to detect it's a TinyPICO at compile time.... (#3567)
#ifdef ARDUINO_TINYPICO
   // It's a TinyPICO!
#endif
2020-01-20 16:06:25 +02:00
e7c9813625 Added Piranha ESP-32 and Metro ESP-32 boards (#3542)
Added two boards from iarduino.ru based on ESP-32
2020-01-20 16:06:06 +02:00
dd78794311 Update CaptivePortal.ino (#3628)
Small change to insure wifi starts off and avoid crashing
2020-01-20 16:04:21 +02:00
0607d36734 HardwareSerial::write(const char*, ...) API compatibility to AVR, ESP8266, et al (#3585)
* API compatibility to AVR, ESP8266, et al

* Add non-blocking HardwareSerial::read(buffer, size) extension (ESP8266 portability)

* Refactor for fewer indirect calls.
2020-01-20 15:54:50 +02:00
6e77f7f3e5 Setting loging level to VERBOSE on Semaphore::take (#3545) 2020-01-20 15:50:19 +02:00
915d45de7d Defined BLE setAdvertisementType (#3535)
Currently we have no way to set BLE Advertisement Type.
We have an initial value of ADV_TYPE_IND and the member is private.

iBeacon should advertise with ADV_TYPE_NONCONN_IND.
esp-idf's example code specifies this value.

93a8603c54/examples/bluetooth/bluedroid/ble/ble_ibeacon/main/ibeacon_demo.c (L57)
2020-01-20 15:42:38 +02:00
lj
c2b37d95e0 Updated BLERemoteCharacteristic to exposre esp_gatt_auth_req_t parame… (#3531)
* Updated BLERemoteCharacteristic to exposre esp_gatt_auth_req_t parameter for readValue and writeValue.

* Updated BLERemoteCharacteristic/Descriptor to expose a setAuth method to allow tweaking the authentication request type for that remotecharacteristic/descriptor without the need to add auth on each read/write.
2020-01-20 15:40:13 +02:00
2f13a960ac Add WIFI_REASON_CONNECTION_FAIL in WiFiGeneric.cpp (#3529)
`WIFI_REASON_CONNECTION_FAIL` has been added to `wifi_err_reason_t` some time ago:  
cec3fca4ad/tools/sdk/include/esp32/esp_wifi_types.h (L95)

But it was still missing from `system_event_reasons` in `WiFiGeneric.cpp` sometimes causing panics here:  
cec3fca4ad/libraries/WiFi/src/WiFiGeneric.cpp (L348)
2020-01-20 15:38:58 +02:00
579e04be25 Cleanup SPI_Multiple_Buses (#3527)
* Utilize prepoc symbols for SPI pins
* Adjusts for GPIO pins when ALTERNATE_PINS is set
2020-01-20 15:37:47 +02:00
5443d7ca93 Add TTGO T Journal Camera module & improve commenting (#3515)
Added pinout for TTGO T Journal device and improved the intent of comments.
2020-01-20 15:33:38 +02:00
7b3c1dfd50 Fix inability to use all buffers in RMT (#3512)
With the >= used let's say you have four RMT inputs, each using 2 channels wide for their receive buffer. This is 4*2 = 8 buffers which is the number of hardware buffers (MAX_CHANNELS). But, for the fourth input the starting buffer will be 6 (this is correct, the buffers used for each input are 0-1, 2-3, 4-5, 6-7). But, 6+2 = 8 which  is MAX_CHANNELS. This is valid but the >= would match against it and abort. It is correct to only abort if the value i+j is only greater than MAX_CHANNELS. Thus, a simple one character fix. Delete the equals sign.
2020-01-20 15:31:44 +02:00
85ef51ffbc BLE: reception support multiple service data (#3502)
* BLE: reception support multiple service data

* fix prev commit, i not inicialized
2020-01-20 15:30:29 +02:00
36075257c2 WString explicit converters to reduce Flash size (#3497)
* WString explicit converters to reduce Flash size

This is a port from the same patch for ESP8266: https://github.com/esp8266/Arduino/pull/6759/files
2020-01-20 15:29:16 +02:00
7de1717640 Fix replacing of headers with overlapping names. Fixes issue #3483 (#3487)
If two headers with overlapping names are added while replace == true, like in:
```cpp
http.addHeader("api_token",  "pMXFOLpinQqajaRQJYMeWObg2XYmcX1");
http.addHeader("token", "1234");
```
then replacing went wrong. This is fixed with this PR.
2020-01-20 15:27:51 +02:00
8869d39d79 Created variant for LilyGo TTGO LoRa32-OLED V2 (#3479)
Hi,

I have added a variant for the LilyGo TTGO LoRa32-OLED V2, which is similar to the LilyGo TTGO LoRa32-OLED V1 but with a different pinout. This will be useful for PlatformIO users, specially because I am also adding the board there as well.

Cheers.
2020-01-20 15:24:19 +02:00
Bob
cfe8526ec8 Add Uri with support for regexUri and globUri (#3441)
* Add Uri with support for staticUri, regexUri and globUri

* Add newline to end of files

* Update example

* Suppress gcc warnings (unused params)
2020-01-20 15:21:01 +02:00
c09ec5bd3d Added MGBOT IOTIK 32A and IOTIK 32B boards (#3427) 2020-01-20 15:19:35 +02:00
d8b2098461 Use IDF's ADC Driver and Add analogReadMilliVolts (#3377) 2020-01-20 15:18:56 +02:00
3fc974f3aa bugfix(touchpad):swap touch8 and touch9 #3584 (#3620) 2020-01-09 08:11:40 +02:00
9ad860758c Fix Memory leak in addApbChangeCallback() (#3560)
* `ledcWriteTone()` added a `apbcallback()` evertime the tone value was non zero.  
* `addApbChangeCallback()` did not detect duplicate callbacks.
* changed the apbcallback list to a double link to support roll forward, roll back execution.  This made the sequences of clock change callback start with the newest registered -> to oldest on the `before` then oldest -> newest after the clock change.  This made the UART debug log output have minimal gibberish during the clock change.
* change how the UART callback handled the MUTEX because if any `apbchangeCallback()` executed a `log_x()` a deadlock would occur.

This fixes #3555
2019-12-30 21:35:29 +02:00
cec3fca4ad Fix BluetoothSerial crash when restart (#3471)
* Update esp32-hal-bt.c

BluetoothSerial crash when restart:  this is because the BT controller remains in state  ESP_BT_CONTROLLER_STATUS_INITED instead of state  ESP_BT_CONTROLLER_STATUS_IDLE after the end() method.
in file esp_bt.h it is specified

> @brief Enable BT controller.
>                Due to a known issue, you cannot call esp_bt_controller_enable() a second time
>                 to change the controller mode dynamically. To change controller mode, call
>                esp_bt_controller_disable() and then call esp_bt_controller_enable() with the new mode.

after **esp_bt_controller_disable()** the controller remains in state INITED so we do call the **esp_bt_controller_deinit()** function to put the controller into state IDLE.

i have modified the **esp32-hal-bt.c** file
line 57 and next
(i have insert the esp_bt_controller_deinit() function so the controller go into Idle state)
```c++
bool btStop(){
    if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){
		log_i("bt stopped");
        return true;
    }
    if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
		log_i("bt enabled");
        if (esp_bt_controller_disable()) {
            log_e("BT Disable failed");
            return false;
        }
        while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED);
    }
    if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED){
		log_i("inited");
		if (esp_bt_controller_deinit()) {
			log_e("BT deint failed");
			return false;
		}
		while (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED);
        return true;
    }
    log_e("BT Stop failed");
    return false;
}
```

* Update esp32-hal-bt.c

remove while to avoid infinite loop
2019-11-11 18:31:09 +01:00
dac493fb92 SPI: Fix discarded-qalifiers warning when compiling with all warnings (#3458)
* SPI: Fix discarded-qalifiers warning when compiling with all warnings

This fixes an error introduced with changeset b847f41 which
tightened the use of const for read-only data. The helper
funtion __transferBytes also requires the const qualifier on
outgoing data. Without this change a warning is displayed
when compiling with the Arduino IDE set to display "All"
compiler warnings.

Tests:
 - Build an ESP32 SPI sketch that uses static const data to send
   to an SPI device using the SPI.transferBytes() API

* SPI:Ensure all local functions are marked static

This audits all functions in the esp32-hal-xpi.c module and
ensures that any functions entirely local to the module are
marked as static.

Tests:
 - Build with Arduino set to show all warnings and ensure none
   are displayed

* SPI: Remove unused local __spiTranslate24 function

This removes the __spiTranslate24() function which is unused.
2019-11-11 17:44:49 +01:00
bc3d11364f Fixed incorrect usage of xEventGroupWaitBits (#3446)
* Fixed incorrect usage of xEventGroupWaitBits

* Added parentheses and `!= 0`
2019-11-11 17:34:01 +01:00
f41beb92bf Fixed so configTime will not crash if tcpip is not initialized (#3470) 2019-11-11 15:50:56 +01:00
8c4ca5a235 Update BLE_client.ino (#3463)
fix typo
2019-11-11 15:49:34 +01:00
b3085d4a8b Add menu items Partition Scheme and Debug Level for node32s (#3455) 2019-11-11 15:47:26 +01:00
547c2d3346 Root CA of webserver has changed, minor changes (#3447) 2019-11-11 15:45:26 +01:00
7d2632c024 Implement Tx only Flush (#3433)
* add option to Flush() to only clear txQueue

Add the option to cause Flush() to just wait for tx data to clear the tx fifo and uart, leave the rx queue and rx fifo as is.

* support tx only flush()

* support tx only Flush()

* support txOnly for Flush()

* compatibility to Stream()

* compatibility for Stream()

* default value error

* default value error

* Update esp32-hal-uart.h

* Update esp32-hal-uart.c

* Update HardwareSerial.cpp

* sp

* correctly implement flushTxOnly()
2019-11-11 15:37:35 +01:00
e59355df71 Docs for lib builder (#3415)
* Docs for lib builder

* Typos and such
2019-11-11 15:30:52 +01:00
ec63d09e54 Fix WiFiGeneric event handler (#3412) 2019-11-11 14:24:50 +01:00
xk
188560e7f3 Some event log messages were off by one. (#3391)
This event name was missing in the list:
d5e2bb12ca/tools/sdk/include/esp32/esp_event_legacy.h (L43)

E.g., it was giving
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 24 - ETH_GOT_IP
When it should have been
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 24 - ETH_DISCONNECTED
2019-11-11 14:21:24 +01:00
91e095f5a7 Add an error message in case of invalid configured dependency mbedTLS. (#3364)
Especially if the user wants to use the library as component in IDF,
there are some pitfalls while doing make menuconfig. One is this missing
dependency which will now fail with a better error message with a hint to
the user how to fix it.

refs #2154 #3215
2019-10-17 09:48:36 +03:00
c8d8dc2265 Added partition size options for TinyPICO (#3358) 2019-10-15 01:32:40 +03:00
b847f41e24 SPI: Ensure all read-only data pointers are marked as const (#3356)
This changes all SPI functions that take data pointers which are
not modified so that the declaration is const. This allows them
to be used with const data (i.e. held in flash). No functional
changes are required.

The defnitions of spiWrite() and spiTransferBytes()  in
esp-hal-spi.h/c have been updated to be consistent.

Tests:
 - Build a simple sketch using SPI.writePattern() and
   SPI.transferBytes()  which uses const data and verify that the
   attached device functions as expected.
2019-10-14 20:39:27 +03:00
611ba8ea8a Update README.md (#3353) 2019-10-14 20:38:04 +03:00
0cab2483e6 Added a description README.md for libraries (#3349) 2019-10-14 20:37:09 +03:00
Luc
79e4339582 Remove warnings if no debug enabled (#3334) 2019-10-08 10:35:42 +03:00
a35035f827 fix authrization problem (#3329)
I compiled the sample "WebServer -> HttpAdvancedAuth". But the right username and password can not login in. I found the file "Webserver.h" may be have some problem. So I fix it. Please check it.
2019-10-08 10:34:36 +03:00
9ef3e2d2a6 Allow sketches to have custom partitions (#3328)
Add a file named `partitions.csv` to your sketch folder and define the partitions inside. In order to not get `Sketch too big`, please select appropriate partition scheme from the board menu
2019-10-07 02:07:15 +03:00
0cdfb0b193 Add support for WiFi long range mode (#3190)
* Add support for WiFi long range mode

* Update WiFiGeneric.cpp
2019-10-06 17:43:15 +03:00
e50613622e Fix typo in SPIFFS and FFAT examples (#3322)
* fix typo in SPIFFS example

* fix typo in FFAT example
2019-10-06 17:29:28 +03:00
24b277ad92 Add readFloat to BLE (#3321)
* Add readFloat

* Add readFloat to BLE
2019-10-06 17:28:53 +03:00
c2b3f2d6af Make yield() overridable (#2991) 2019-10-04 12:49:39 +03:00
8fb8e7d060 CI can be used on windows desktop with msys 2019-10-02 20:03:43 +03:00
048b26547a Update boards_manager.md 2019-10-02 16:06:15 +03:00
b10ed77aaf Update boards_manager.md 2019-10-02 15:58:58 +03:00
4638628873 Wait for client.available() to prevent ESP32 crashes (#3154)
* Wait for client.available() to prevent ESP32 crashes

* Removed user-specific SSID & passphrase
2019-10-02 14:45:42 +03:00
6f70e27011 Base64::encode : const correctness / String by reference passing (#3314)
Avoid passing String by-value, which is slightly less efficient
as it involves a full copy-constructor/tempstring creation.
2019-10-02 14:29:24 +03:00
d0b064a1ee Update CI scripts for better error handling (#3316) 2019-10-02 11:58:02 +03:00
85c77a9c3f Fix CI Builds for Linux (#3313) 2019-10-01 23:13:08 +03:00
c8e3f0c732 Support Pi 4 on 64bit kernel 2019-10-01 22:15:13 +03:00
5ad468f9dc Add ARM toolchain 2019-10-01 21:48:03 +03:00
38c4c06108 Support for Master mode, Pin and SSP (#3219)
* 20190916 - initial: support for Master mode, Pin and SSP

* 20190916 - initial: Add example app for Master mode

* 20190916 - initial: Force another build

* 20190916 - connect would use resolved address as preference and remove now redundant _remote_address

* 20190916 - rework set/reset/default pin logic

* 20190916 - cleanup: remove static vars, add/use constants, fix typos

* 20190916 - fix build issues and implement geoup events for status verification.

* 20190916 - remove extra lines,misc

* 20190916 - rework ESP_BT_GAP_DISC_RES_EVT, added SPP_DISCONNECTED bit for disconnect event. + timeout for disconnect()

* 20190916 - Small log change to improve log sequencing

* 20190916 - remove static from local vars

* 20190916 - Limited scope and duration for the scan, log device address during scan in info mode as it is very difficult to find out sometimes. Fixed get_name_from_eir() not resetting the name when called.

* 20190916 - break property for loop during scan when name matches.

* 20190916 - misc

* 20190916 - SPP_DISCONNECT state updates

* 20190916 - formatting, remove some strange syntax from initiator code

* 20190916 - Add comments to the example about connect(...) usage and timeouts

* 20190916 - fix disconnect() without timeout

* 20190916 - Add example comment to view BT address and name during connect(name)

* 20190916 - wording in example comments

* 20190916 - rework connect() and disconnect() methods to help with concurrency and more authoritative status returned back to caller. Automatic disconnect in connect() methods

* 20190916 - optimize code

* 20190916 - optimize code - more

* 20190916 - add timeout for pin set

* 20190916 - change scan mode to ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE

* 20190916 - update example code slightly

* 20190916 - increase READY_TIMEOUT to 10 secs

* 20190916 - typo in example and move waitForConnect() to static area

* 20190916 - update example comments

* 20190916 - update example comments

* 20190916 - update example comments

* 20190916 - add new example to remove paired devices from ESP32

* 20190916 - correct typo in example

* 20190916 - update example comment, add remove_bond_device() method for convenience.

* 20190916 - reword example comment.

* 20190916 - rename remove_bond_device()

* 20190916 - rename removePairedDevice() to unpairDevice()

* 20190916 - code review changes

* 20190916 - fix return value in setup() od example
2019-10-01 17:34:46 +03:00
b334b2c2f9 Add config, menu partition Wrover (#3147)
* add config, menu partition Wrover

* fix all boards
2019-10-01 17:10:16 +03:00
8a46697168 Fix for issue_3209. (#3210)
#include "esp32-hal-log.h" is mandatory is order to build BLEDevice.cpp.
It can't be left up to a compiler variable.
2019-10-01 16:32:47 +03:00
270a2759d9 Add pages action (#3311)
* Add script to handle updates to the docs folder

* Create gh-pages.yml

* Update on-pages.sh
2019-10-01 16:04:20 +03:00
01d9345d28 Update development JSON location 2019-10-01 12:14:07 +03:00
1098 changed files with 55146 additions and 54518 deletions

42
.github/scripts/install-arduino-core-esp32.sh vendored Normal file → Executable file
View File

@ -2,39 +2,33 @@
export ARDUINO_ESP32_PATH="$ARDUINO_USR_PATH/hardware/espressif/esp32"
if [ ! -d "$ARDUINO_ESP32_PATH" ]; then
echo "Installing ESP32 Arduino Core in '$ARDUINO_ESP32_PATH'..."
echo "Installing ESP32 Arduino Core ..."
script_init_path="$PWD"
mkdir -p "$ARDUINO_USR_PATH/hardware/espressif" && \
mkdir -p "$ARDUINO_USR_PATH/hardware/espressif"
cd "$ARDUINO_USR_PATH/hardware/espressif"
if [ $? -ne 0 ]; then exit 1; fi
if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ]; then
echo "Linking Core..." && \
ln -s $GITHUB_WORKSPACE esp32
else
echo "Cloning Core Repository..." && \
git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "ERROR: GIT clone failed"; exit 1; fi
fi
cd esp32 && \
echo "Updating submodules..." && \
git submodule update --init --recursive > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "ERROR: Submodule update failed"; exit 1; fi
echo "Installing Python Serial..." && \
echo "Installing Python Serial ..."
pip install pyserial > /dev/null
if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
if [ "$OS_IS_WINDOWS" == "1" ]; then
echo "Installing Python Requests..."
echo "Installing Python Requests ..."
pip install requests > /dev/null
if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
fi
echo "Downloading the tools and the toolchain..."
cd tools && python get.py > /dev/null
if [ $? -ne 0 ]; then echo "ERROR: Download failed"; exit 1; fi
if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ]; then
echo "Linking Core..."
ln -s $GITHUB_WORKSPACE esp32
else
echo "Cloning Core Repository..."
git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1
fi
#echo "Updating Submodules ..."
cd esp32
#git submodule update --init --recursive > /dev/null 2>&1
echo "Installing Platform Tools ..."
cd tools && python get.py
cd $script_init_path
echo "ESP32 Arduino has been installed in '$ARDUINO_ESP32_PATH'"

29
.github/scripts/install-arduino-ide.sh vendored Normal file → Executable file
View File

@ -12,7 +12,7 @@ if [[ "$OSTYPE" == "linux"* ]]; then
OS_NAME="linux32"
elif [[ "$OSBITS" == "x86_64" ]]; then
OS_NAME="linux64"
elif [[ "$OSBITS" == "armv7l" ]]; then
elif [[ "$OSBITS" == "armv7l" || "$OSBITS" == "aarch64" ]]; then
OS_NAME="linuxarm"
else
OS_NAME="$OSTYPE-$OSBITS"
@ -40,34 +40,32 @@ ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
if [ "$OS_IS_MACOS" == "1" ]; then
export ARDUINO_IDE_PATH="/Applications/Arduino.app/Contents/Java"
export ARDUINO_USR_PATH="$HOME/Documents/Arduino"
elif [ "$OS_IS_WINDOWS" == "1" ]; then
export ARDUINO_IDE_PATH="$HOME/arduino_ide"
export ARDUINO_USR_PATH="$HOME/Documents/Arduino"
else
export ARDUINO_IDE_PATH="$HOME/arduino_ide"
export ARDUINO_USR_PATH="$HOME/Arduino"
fi
if [ ! -d "$ARDUINO_IDE_PATH" ]; then
echo "Installing Arduino IDE on $OS_NAME..."
echo "Downloading 'arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT' to 'arduino.$ARCHIVE_FORMAT'..."
echo "Installing Arduino IDE on $OS_NAME ..."
echo "Downloading 'arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT' to 'arduino.$ARCHIVE_FORMAT' ..."
if [ "$OS_IS_LINUX" == "1" ]; then
wget -O "arduino.$ARCHIVE_FORMAT" "https://www.arduino.cc/download.php?f=/arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "ERROR: Download failed"; exit 1; fi
echo "Extracting 'arduino.$ARCHIVE_FORMAT'..."
echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..."
tar xf "arduino.$ARCHIVE_FORMAT" > /dev/null
if [ $? -ne 0 ]; then exit 1; fi
mv arduino-nightly "$ARDUINO_IDE_PATH"
else
curl -o "arduino.$ARCHIVE_FORMAT" -L "https://www.arduino.cc/download.php?f=/arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "ERROR: Download failed"; exit 1; fi
echo "Extracting 'arduino.$ARCHIVE_FORMAT'..."
echo "Extracting 'arduino.$ARCHIVE_FORMAT' ..."
unzip "arduino.$ARCHIVE_FORMAT" > /dev/null
if [ $? -ne 0 ]; then exit 1; fi
if [ "$OS_IS_MACOS" == "1" ]; then
mv "Arduino.app" "/Applications/Arduino.app"
else
mv arduino-nightly "$ARDUINO_IDE_PATH"
fi
fi
if [ $? -ne 0 ]; then exit 1; fi
rm -rf "arduino.$ARCHIVE_FORMAT"
mkdir -p "$ARDUINO_USR_PATH/libraries"
@ -95,7 +93,7 @@ function build_sketch(){ # build_sketch <fqbn> <path-to-ino> [extra-options]
fi
echo ""
echo "Compiling '"$(basename "$sketch")"'..."
echo "Compiling '"$(basename "$sketch")"' ..."
mkdir -p "$ARDUINO_BUILD_DIR"
mkdir -p "$ARDUINO_CACHE_DIR"
$ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 \
@ -115,9 +113,13 @@ function build_sketch(){ # build_sketch <fqbn> <path-to-ino> [extra-options]
function count_sketches() # count_sketches <examples-path>
{
local examples="$1"
rm -rf sketches.txt
if [ ! -d "$examples" ]; then
touch sketches.txt
return 0
fi
local sketches=$(find $examples -name *.ino)
local sketchnum=0
rm -rf sketches.txt
for sketch in $sketches; do
local sketchdir=$(dirname $sketch)
local sketchdirname=$(basename $sketchdir)
@ -163,8 +165,10 @@ function build_sketches() # build_sketches <fqbn> <examples-path> <chunk> <total
return 1
fi
set +e
count_sketches "$examples"
local sketchcount=$?
set -e
local sketches=$(cat sketches.txt)
rm -rf sketches.txt
@ -214,4 +218,3 @@ function build_sketches() # build_sketches <fqbn> <examples-path> <chunk> <total
done
return 0
}

68
.github/scripts/install-platformio-esp32.sh vendored Normal file → Executable file
View File

@ -2,40 +2,34 @@
export PLATFORMIO_ESP32_PATH="$HOME/.platformio/packages/framework-arduinoespressif32"
echo "Installing Python Wheel..."
echo "Installing Python Wheel ..."
pip install wheel > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
echo "Installing PlatformIO..."
echo "Installing PlatformIO ..."
pip install -U https://github.com/platformio/platformio/archive/develop.zip > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
echo "Installing Platform ESP32..."
echo "Installing Platform ESP32 ..."
python -m platformio platform install https://github.com/platformio/platform-espressif32.git#feature/stage > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
echo "Replacing the framework version..."
echo "Replacing the framework version ..."
if [[ "$OSTYPE" == "darwin"* ]]; then
sed 's/https:\/\/github\.com\/espressif\/arduino-esp32\.git/*/' "$HOME/.platformio/platforms/espressif32/platform.json" > "platform.json" && \
sed 's/https:\/\/github\.com\/espressif\/arduino-esp32\.git/*/' "$HOME/.platformio/platforms/espressif32/platform.json" > "platform.json"
mv -f "platform.json" "$HOME/.platformio/platforms/espressif32/platform.json"
else
sed -i 's/https:\/\/github\.com\/espressif\/arduino-esp32\.git/*/' "$HOME/.platformio/platforms/espressif32/platform.json"
fi
if [ $? -ne 0 ]; then echo "ERROR: Replace failed"; exit 1; fi
if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ]; then
echo "Linking Core..." && \
echo "Linking Core..."
ln -s $GITHUB_WORKSPACE "$PLATFORMIO_ESP32_PATH"
else
echo "Cloning Core Repository..." && \
echo "Cloning Core Repository ..."
git clone https://github.com/espressif/arduino-esp32.git "$PLATFORMIO_ESP32_PATH" > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "ERROR: GIT clone failed"; exit 1; fi
fi
echo "PlatformIO for ESP32 has been installed"
echo ""
function build_pio_sketch(){ # build_pio_sketch <board> <path-to-ino>
if [ "$#" -lt 2 ]; then
echo "ERROR: Illegal number of parameters"
@ -43,20 +37,24 @@ function build_pio_sketch(){ # build_pio_sketch <board> <path-to-ino>
return 1
fi
local board="$1"
local sketch="$2"
local sketch_dir=$(dirname "$sketch")
echo ""
echo "Compiling '"$(basename "$sketch")"'..."
python -m platformio ci --board "$board" "$sketch_dir" --project-option="board_build.partitions = huge_app.csv"
local board="$1"
local sketch="$2"
local sketch_dir=$(dirname "$sketch")
echo ""
echo "Compiling '"$(basename "$sketch")"' ..."
python -m platformio ci --board "$board" "$sketch_dir" --project-option="board_build.partitions = huge_app.csv"
}
function count_sketches() # count_sketches <examples-path>
{
local examples="$1"
local examples="$1"
rm -rf sketches.txt
if [ ! -d "$examples" ]; then
touch sketches.txt
return 0
fi
local sketches=$(find $examples -name *.ino)
local sketchnum=0
rm -rf sketches.txt
for sketch in $sketches; do
local sketchdir=$(dirname $sketch)
local sketchdirname=$(basename $sketchdir)
@ -91,35 +89,37 @@ function build_pio_sketches() # build_pio_sketches <board> <examples-path> <chun
chunks_num="1"
fi
if [ "$chunks_num" -le 0 ]; then
echo "ERROR: Chunks count must be positive number"
return 1
fi
if [ "$chunk_idex" -ge "$chunks_num" ]; then
echo "ERROR: Chunk index must be less than chunks count"
return 1
fi
if [ "$chunks_num" -le 0 ]; then
echo "ERROR: Chunks count must be positive number"
return 1
fi
if [ "$chunk_idex" -ge "$chunks_num" ]; then
echo "ERROR: Chunk index must be less than chunks count"
return 1
fi
set +e
count_sketches "$examples"
local sketchcount=$?
set -e
local sketches=$(cat sketches.txt)
rm -rf sketches.txt
local chunk_size=$(( $sketchcount / $chunks_num ))
local all_chunks=$(( $chunks_num * $chunk_size ))
if [ "$all_chunks" -lt "$sketchcount" ]; then
chunk_size=$(( $chunk_size + 1 ))
chunk_size=$(( $chunk_size + 1 ))
fi
local start_index=$(( $chunk_idex * $chunk_size ))
if [ "$sketchcount" -le "$start_index" ]; then
echo "Skipping job"
return 0
echo "Skipping job"
return 0
fi
local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
if [ "$end_index" -gt "$sketchcount" ]; then
end_index=$sketchcount
end_index=$sketchcount
fi
local start_num=$(( $start_index + 1 ))
@ -141,7 +141,7 @@ function build_pio_sketches() # build_pio_sketches <board> <examples-path> <chun
sketchnum=$(($sketchnum + 1))
if [ "$sketchnum" -le "$start_index" ] \
|| [ "$sketchnum" -gt "$end_index" ]; then
continue
continue
fi
build_pio_sketch "$board" "$sketch"
local result=$?

131
.github/scripts/on-pages.sh vendored Normal file
View File

@ -0,0 +1,131 @@
#/bin/bash
set -e
function get_file_size(){
local file="$1"
if [[ "$OSTYPE" == "darwin"* ]]; then
eval `stat -s "$file"`
local res="$?"
echo "$st_size"
return $res
else
stat --printf="%s" "$file"
return $?
fi
}
#git_remove_from_pages <file>
function git_remove_from_pages(){
local path=$1
local info=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.object+json" -X GET "https://api.github.com/repos/$GITHUB_REPOSITORY/contents/$path?ref=gh-pages"`
local type=`echo "$info" | jq -r '.type'`
if [ ! $type == "file" ]; then
if [ ! $type == "null" ]; then
echo "Wrong type '$type'"
else
echo "File is not on Pages"
fi
return 0
fi
local sha=`echo "$info" | jq -r '.sha'`
local message="Deleting "$(basename $path)
local json="{\"branch\":\"gh-pages\",\"message\":\"$message\",\"sha\":\"$sha\"}"
echo "$json" | curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" -X DELETE --data @- "https://api.github.com/repos/$GITHUB_REPOSITORY/contents/$path"
}
function git_upload_to_pages(){
local path=$1
local src=$2
if [ ! -f "$src" ]; then
>&2 echo "Input is not a file! Aborting..."
return 1
fi
local info=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.object+json" -X GET "https://api.github.com/repos/$GITHUB_REPOSITORY/contents/$path?ref=gh-pages"`
local type=`echo "$info" | jq -r '.type'`
local message=$(basename $path)
local sha=""
local content=""
if [ $type == "file" ]; then
sha=`echo "$info" | jq -r '.sha'`
sha=",\"sha\":\"$sha\""
message="Updating $message"
elif [ ! $type == "null" ]; then
>&2 echo "Wrong type '$type'"
return 1
else
message="Creating $message"
fi
content=`base64 -i "$src"`
data="{\"branch\":\"gh-pages\",\"message\":\"$message\",\"content\":\"$content\"$sha}"
echo "$data" | curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" -X PUT --data @- "https://api.github.com/repos/$GITHUB_REPOSITORY/contents/$path"
}
function git_safe_upload_to_pages(){
local path=$1
local file="$2"
local name=$(basename "$file")
local size=`get_file_size "$file"`
local upload_res=`git_upload_to_pages "$path" "$file"`
if [ $? -ne 0 ]; then
>&2 echo "ERROR: Failed to upload '$name' ($?)"
return 1
fi
up_size=`echo "$upload_res" | jq -r '.content.size'`
if [ $up_size -ne $size ]; then
>&2 echo "ERROR: Uploaded size does not match! $up_size != $size"
#git_delete_asset
return 1
fi
echo "$upload_res" | jq -r '.content.download_url'
return $?
}
EVENT_JSON=`cat $GITHUB_EVENT_PATH`
pages_added=`echo "$EVENT_JSON" | jq -r '.commits[].added[]'`
pages_modified=`echo "$EVENT_JSON" | jq -r '.commits[].modified[]'`
pages_removed=`echo "$EVENT_JSON" | jq -r '.commits[].removed[]'`
for page in $pages_added; do
if [[ $page != "README.md" && $page != "docs/"* ]]; then
continue
fi
echo "Adding '$page' to pages ..."
if [[ $page == "README.md" ]]; then
git_safe_upload_to_pages "index.md" "README.md"
else
git_safe_upload_to_pages "$page" "$page"
fi
done
for page in $pages_modified; do
if [[ $page != "README.md" && $page != "docs/"* ]]; then
continue
fi
echo "Modifying '$page' ..."
if [[ $page == "README.md" ]]; then
git_safe_upload_to_pages "index.md" "README.md"
else
git_safe_upload_to_pages "$page" "$page"
fi
done
for page in $pages_removed; do
if [[ $page != "README.md" && $page != "docs/"* ]]; then
continue
fi
echo "Removing '$page' from pages ..."
if [[ $page == "README.md" ]]; then
git_remove_from_pages "README.md" > /dev/null
else
git_remove_from_pages "$page" > /dev/null
fi
done
echo
echo "DONE!"

View File

@ -1,5 +1,7 @@
#!/bin/bash
set -e
if [ ! -z "$TRAVIS_TAG" ]; then
echo "Skipping Test: Tagged build"
exit 0
@ -28,8 +30,8 @@ elif [ "$CHUNK_INDEX" -eq "$CHUNKS_CNT" ]; then
BUILD_PIO=1
fi
echo "Updating submodules ..."
git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1
#echo "Updating submodules ..."
#git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1
if [ "$BUILD_PIO" -eq 0 ]; then
# ArduinoIDE Test
@ -39,20 +41,17 @@ if [ "$BUILD_PIO" -eq 0 ]; then
if [ "$OS_IS_WINDOWS" == "1" ]; then
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/AzureIoT/examples/GetStarted/GetStarted.ino" && \
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
elif [ "$OS_IS_MACOS" == "1" ]; then
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/AzureIoT/examples/GetStarted/GetStarted.ino" && \
build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
else
# CMake Test
if [ "$CHUNK_INDEX" -eq 0 ]; then
bash "$ARDUINO_ESP32_PATH/.github/scripts/check-cmakelists.sh"
if [ $? -ne 0 ]; then exit 1; fi
fi
build_sketches "$FQBN" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT"
fi
@ -64,8 +63,6 @@ else
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/AzureIoT/examples/GetStarted/GetStarted.ino" && \
build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
#build_pio_sketches esp32dev "$PLATFORMIO_ESP32_PATH/libraries"
fi
if [ $? -ne 0 ]; then exit 1; fi

21
.github/workflows/gh-pages.yml vendored Normal file
View File

@ -0,0 +1,21 @@
name: GitHub Pages CI
on:
push:
branches:
- master
paths:
- 'README.md'
- 'docs/**'
jobs:
build-pages:
name: Build GitHub Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Copy Files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bash ./.github/scripts/on-pages.sh

View File

@ -19,6 +19,9 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Build Sketches
run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} 15
@ -32,6 +35,9 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Build Sketches
run: bash ./.github/scripts/on-push.sh
@ -45,5 +51,8 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Build Sketches
run: bash ./.github/scripts/on-push.sh 1 1 #equal and non-zero to trigger PIO

View File

@ -11,6 +11,9 @@ jobs:
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Build Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "libraries/AzureIoT"]
path = libraries/AzureIoT
url = https://github.com/VSChina/ESP32_AzureIoT_Arduino

View File

@ -78,66 +78,6 @@ set(LIBRARY_SRCS
libraries/Wire/src/Wire.cpp
)
set(AZURE_SRCS
libraries/AzureIoT/src/az_iot/azureiotcerts.c
libraries/AzureIoT/src/az_iot/c-utility/pal/agenttime.c
libraries/AzureIoT/src/az_iot/c-utility/pal/dns_async.c
libraries/AzureIoT/src/az_iot/c-utility/pal/freertos/lock.c
libraries/AzureIoT/src/az_iot/c-utility/pal/freertos/threadapi.c
libraries/AzureIoT/src/az_iot/c-utility/pal/freertos/tickcounter.c
libraries/AzureIoT/src/az_iot/c-utility/pal/lwip/sntp_lwip.c
libraries/AzureIoT/src/az_iot/c-utility/pal/socket_async.c
libraries/AzureIoT/src/az_iot/c-utility/pal/src/platform_openssl_compact.c
libraries/AzureIoT/src/az_iot/c-utility/pal/src/tlsio_openssl_compact.c
libraries/AzureIoT/src/az_iot/c-utility/pal/tlsio_options.c
libraries/AzureIoT/src/az_iot/c-utility/src/base64.c
libraries/AzureIoT/src/az_iot/c-utility/src/buffer.c
libraries/AzureIoT/src/az_iot/c-utility/src/connection_string_parser.c
libraries/AzureIoT/src/az_iot/c-utility/src/consolelogger.c
libraries/AzureIoT/src/az_iot/c-utility/src/constbuffer.c
libraries/AzureIoT/src/az_iot/c-utility/src/constmap.c
libraries/AzureIoT/src/az_iot/c-utility/src/crt_abstractions.c
libraries/AzureIoT/src/az_iot/c-utility/src/doublylinkedlist.c
libraries/AzureIoT/src/az_iot/c-utility/src/gballoc.c
libraries/AzureIoT/src/az_iot/c-utility/src/gb_stdio.c
libraries/AzureIoT/src/az_iot/c-utility/src/gb_time.c
libraries/AzureIoT/src/az_iot/c-utility/src/hmac.c
libraries/AzureIoT/src/az_iot/c-utility/src/hmacsha256.c
libraries/AzureIoT/src/az_iot/c-utility/src/httpapiex.c
libraries/AzureIoT/src/az_iot/c-utility/src/httpapiexsas.c
libraries/AzureIoT/src/az_iot/c-utility/src/httpheaders.c
libraries/AzureIoT/src/az_iot/c-utility/src/http_proxy_io.c
libraries/AzureIoT/src/az_iot/c-utility/src/map.c
libraries/AzureIoT/src/az_iot/c-utility/src/optionhandler.c
libraries/AzureIoT/src/az_iot/c-utility/src/sastoken.c
libraries/AzureIoT/src/az_iot/c-utility/src/sha1.c
libraries/AzureIoT/src/az_iot/c-utility/src/sha224.c
libraries/AzureIoT/src/az_iot/c-utility/src/sha384-512.c
libraries/AzureIoT/src/az_iot/c-utility/src/singlylinkedlist.c
libraries/AzureIoT/src/az_iot/c-utility/src/strings.c
libraries/AzureIoT/src/az_iot/c-utility/src/string_tokenizer.c
libraries/AzureIoT/src/az_iot/c-utility/src/urlencode.c
libraries/AzureIoT/src/az_iot/c-utility/src/usha.c
libraries/AzureIoT/src/az_iot/c-utility/src/vector.c
libraries/AzureIoT/src/az_iot/c-utility/src/xio.c
libraries/AzureIoT/src/az_iot/c-utility/src/xlogging.c
libraries/AzureIoT/src/az_iot/iothub_client/src/blob.c
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client_authorization.c
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client.c
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client_ll.c
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client_retry_control.c
libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_message.c
libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransport.c
libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransportmqtt.c
libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransport_mqtt_common.c
libraries/AzureIoT/src/az_iot/iothub_client/src/version.c
libraries/AzureIoT/src/az_iot/umqtt/src/mqtt_client.c
libraries/AzureIoT/src/az_iot/umqtt/src/mqtt_codec.c
libraries/AzureIoT/src/az_iot/umqtt/src/mqtt_message.c
libraries/AzureIoT/src/AzureIotHub.cpp
libraries/AzureIoT/src/Esp32MQTTClient.cpp
)
set(BLE_SRCS
libraries/BLE/src/BLE2902.cpp
libraries/BLE/src/BLE2904.cpp
@ -170,14 +110,13 @@ set(BLE_SRCS
libraries/BLE/src/GeneralUtils.cpp
)
set(COMPONENT_SRCS ${CORE_SRCS} ${LIBRARY_SRCS} ${AZURE_SRCS} ${BLE_SRCS})
set(COMPONENT_SRCS ${CORE_SRCS} ${LIBRARY_SRCS} ${BLE_SRCS})
set(COMPONENT_ADD_INCLUDEDIRS
variants/esp32/
cores/esp32/
libraries/ArduinoOTA/src
libraries/AsyncUDP/src
libraries/AzureIoT/src
libraries/BLE/src
libraries/BluetoothSerial/src
libraries/DNSServer/src
@ -205,12 +144,7 @@ set(COMPONENT_ADD_INCLUDEDIRS
set(COMPONENT_PRIV_INCLUDEDIRS cores/esp32/libb64)
set(COMPONENT_REQUIRES spi_flash mbedtls mdns ethernet)
set(COMPONENT_REQUIRES spi_flash mbedtls mdns esp_adc_cal)
set(COMPONENT_PRIV_REQUIRES fatfs nvs_flash app_update spiffs bootloader_support openssl bt)
register_component()
set_source_files_properties(libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransport_mqtt_common.c
PROPERTIES COMPILE_FLAGS
-Wno-maybe-uninitialized
)

View File

@ -36,12 +36,12 @@ You can use [EspExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecod
### Issue/Bug report template
Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labelled as [for reference](https://github.com/espressif/arduino-esp32/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3A%22for%20reference%22%20).
Finally, if you're sure no one else had the issue, follow the [ISSUE_TEMPLATE](docs/ISSUE_TEMPLATE.md) while reporting any issue.
Finally, if you are sure no one else had the issue, follow the [ISSUE_TEMPLATE](docs/ISSUE_TEMPLATE.md) while reporting any issue.
### ESP32Dev Board PINMAP
![Pin Functions](docs/esp32_pinmap.png)
### Hint
### Tip
Sometimes to program ESP32 via serial you must keep GPIO0 LOW during the programming process

View File

@ -173,19 +173,34 @@ esp32wrover.build.boot=dio
esp32wrover.build.partitions=default
esp32wrover.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue
esp32wrover.menu.PartitionScheme.default=Default
esp32wrover.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
esp32wrover.menu.PartitionScheme.default.build.partitions=default
esp32wrover.menu.PartitionScheme.minimal=Minimal (2MB FLASH)
esp32wrover.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS)
esp32wrover.menu.PartitionScheme.defaultffat.build.partitions=default_ffat
esp32wrover.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT)
esp32wrover.menu.PartitionScheme.default_8MB.build.partitions=default_8MB
esp32wrover.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS)
esp32wrover.menu.PartitionScheme.minimal.build.partitions=minimal
esp32wrover.menu.PartitionScheme.no_ota=No OTA (Large APP)
esp32wrover.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS)
esp32wrover.menu.PartitionScheme.no_ota.build.partitions=no_ota
esp32wrover.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
esp32wrover.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA)
esp32wrover.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS)
esp32wrover.menu.PartitionScheme.noota_3g.build.partitions=noota_3g
esp32wrover.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576
esp32wrover.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS)
esp32wrover.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat
esp32wrover.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152
esp32wrover.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS)
esp32wrover.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat
esp32wrover.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576
esp32wrover.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS)
esp32wrover.menu.PartitionScheme.huge_app.build.partitions=huge_app
esp32wrover.menu.PartitionScheme.huge_app.upload.maximum_size=3145728
esp32wrover.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
esp32wrover.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)
esp32wrover.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
esp32wrover.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
esp32wrover.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT)
esp32wrover.menu.PartitionScheme.fatflash.build.partitions=ffat
esp32wrover.menu.FlashMode.qio=QIO
esp32wrover.menu.FlashMode.qio.build.flash_mode=dio
@ -309,7 +324,7 @@ tinypico.serial.disableRTS=true
tinypico.build.mcu=esp32
tinypico.build.core=esp32
tinypico.build.variant=pico32
tinypico.build.board=ESP32_PICO
tinypico.build.board=TINYPICO
tinypico.build.f_cpu=240000000L
tinypico.build.flash_size=4MB
@ -319,6 +334,15 @@ tinypico.build.boot=dio
tinypico.build.partitions=default
tinypico.build.defines=
tinypico.menu.PartitionScheme.default=Default
tinypico.menu.PartitionScheme.default.build.partitions=default
tinypico.menu.PartitionScheme.no_ota=No OTA (Large APP)
tinypico.menu.PartitionScheme.no_ota.build.partitions=no_ota
tinypico.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
tinypico.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
tinypico.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
tinypico.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
tinypico.menu.UploadSpeed.921600=921600
tinypico.menu.UploadSpeed.921600.upload.speed=921600
tinypico.menu.UploadSpeed.115200=115200
@ -1367,6 +1391,15 @@ node32s.build.boot=dio
node32s.build.partitions=default
node32s.build.defines=
node32s.menu.PartitionScheme.default=Default
node32s.menu.PartitionScheme.default.build.partitions=default
node32s.menu.PartitionScheme.no_ota=No OTA (Large APP)
node32s.menu.PartitionScheme.no_ota.build.partitions=no_ota
node32s.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
node32s.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
node32s.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
node32s.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
node32s.menu.FlashFreq.80=80MHz
node32s.menu.FlashFreq.80.build.flash_freq=80m
node32s.menu.FlashFreq.40=40MHz
@ -1387,6 +1420,19 @@ node32s.menu.UploadSpeed.460800.upload.speed=460800
node32s.menu.UploadSpeed.512000.windows=512000
node32s.menu.UploadSpeed.512000.upload.speed=512000
node32s.menu.DebugLevel.none=None
node32s.menu.DebugLevel.none.build.code_debug=0
node32s.menu.DebugLevel.error=Error
node32s.menu.DebugLevel.error.build.code_debug=1
node32s.menu.DebugLevel.warn=Warn
node32s.menu.DebugLevel.warn.build.code_debug=2
node32s.menu.DebugLevel.info=Info
node32s.menu.DebugLevel.info.build.code_debug=3
node32s.menu.DebugLevel.debug=Debug
node32s.menu.DebugLevel.debug.build.code_debug=4
node32s.menu.DebugLevel.verbose=Verbose
node32s.menu.DebugLevel.verbose.build.code_debug=5
##############################################################
hornbill32dev.name=Hornbill ESP32 Dev
@ -3070,8 +3116,8 @@ CoreESP32.upload.maximum_size=1310720
CoreESP32.upload.maximum_data_size=327680
CoreESP32.upload.wait_for_upload_port=true
CoreESP32.serial.disableDTR=true
CoreESP32.serial.disableRTS=true
CoreESP32.serial.disableDTR=false
CoreESP32.serial.disableRTS=false
CoreESP32.build.mcu=esp32
CoreESP32.build.core=esp32
@ -3085,6 +3131,24 @@ CoreESP32.build.boot=dio
CoreESP32.build.partitions=default
CoreESP32.build.defines=
CoreESP32.menu.PSRAM.disabled=Disabled
CoreESP32.menu.PSRAM.disabled.build.defines=
CoreESP32.menu.PSRAM.enabled=Enabled
CoreESP32.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue
CoreESP32.menu.PartitionScheme.default=Default
CoreESP32.menu.PartitionScheme.default.build.partitions=default
CoreESP32.menu.PartitionScheme.minimal=Minimal (2MB FLASH)
CoreESP32.menu.PartitionScheme.minimal.build.partitions=minimal
CoreESP32.menu.PartitionScheme.no_ota=No OTA (Large APP)
CoreESP32.menu.PartitionScheme.no_ota.build.partitions=no_ota
CoreESP32.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
CoreESP32.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
CoreESP32.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
CoreESP32.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
CoreESP32.menu.PartitionScheme.fatflash=16M Fat
CoreESP32.menu.PartitionScheme.fatflash.build.partitions=ffat
CoreESP32.menu.FlashFreq.80=80MHz
CoreESP32.menu.FlashFreq.80.build.flash_freq=80m
CoreESP32.menu.FlashFreq.40=40MHz
@ -3105,6 +3169,19 @@ CoreESP32.menu.UploadSpeed.460800.upload.speed=460800
CoreESP32.menu.UploadSpeed.512000.windows=512000
CoreESP32.menu.UploadSpeed.512000.upload.speed=512000
CoreESP32.menu.DebugLevel.none=None
CoreESP32.menu.DebugLevel.none.build.code_debug=0
CoreESP32.menu.DebugLevel.error=Error
CoreESP32.menu.DebugLevel.error.build.code_debug=1
CoreESP32.menu.DebugLevel.warn=Warn
CoreESP32.menu.DebugLevel.warn.build.code_debug=2
CoreESP32.menu.DebugLevel.info=Info
CoreESP32.menu.DebugLevel.info.build.code_debug=3
CoreESP32.menu.DebugLevel.debug=Debug
CoreESP32.menu.DebugLevel.debug.build.code_debug=4
CoreESP32.menu.DebugLevel.verbose=Verbose
CoreESP32.menu.DebugLevel.verbose.build.code_debug=5
##############################################################
@ -4189,6 +4266,51 @@ vintlabs-devkit-v1.menu.UploadSpeed.460800.upload.speed=460800
vintlabs-devkit-v1.menu.UploadSpeed.512000.windows=512000
vintlabs-devkit-v1.menu.UploadSpeed.512000.upload.speed=512000
vintlabs-devkit-v1.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
vintlabs-devkit-v1.menu.PartitionScheme.default.build.partitions=default
vintlabs-devkit-v1.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS)
vintlabs-devkit-v1.menu.PartitionScheme.defaultffat.build.partitions=default_ffat
vintlabs-devkit-v1.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT)
vintlabs-devkit-v1.menu.PartitionScheme.default_8MB.build.partitions=default_8MB
vintlabs-devkit-v1.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336
vintlabs-devkit-v1.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS)
vintlabs-devkit-v1.menu.PartitionScheme.minimal.build.partitions=minimal
vintlabs-devkit-v1.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS)
vintlabs-devkit-v1.menu.PartitionScheme.no_ota.build.partitions=no_ota
vintlabs-devkit-v1.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
vintlabs-devkit-v1.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS)
vintlabs-devkit-v1.menu.PartitionScheme.noota_3g.build.partitions=noota_3g
vintlabs-devkit-v1.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576
vintlabs-devkit-v1.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS)
vintlabs-devkit-v1.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat
vintlabs-devkit-v1.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152
vintlabs-devkit-v1.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS)
vintlabs-devkit-v1.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat
vintlabs-devkit-v1.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576
vintlabs-devkit-v1.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS)
vintlabs-devkit-v1.menu.PartitionScheme.huge_app.build.partitions=huge_app
vintlabs-devkit-v1.menu.PartitionScheme.huge_app.upload.maximum_size=3145728
vintlabs-devkit-v1.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)
vintlabs-devkit-v1.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
vintlabs-devkit-v1.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
vintlabs-devkit-v1.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT)
vintlabs-devkit-v1.menu.PartitionScheme.fatflash.build.partitions=ffat
vintlabs-devkit-v1.menu.PartitionScheme.fatflash.upload.maximum_size=2097152
vintlabs-devkit-v1.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS)
vintlabs-devkit-v1.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB
vintlabs-devkit-v1.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728
vintlabs-devkit-v1.menu.FlashSize.4M=4MB (32Mb)
vintlabs-devkit-v1.menu.FlashSize.4M.build.flash_size=4MB
vintlabs-devkit-v1.menu.FlashSize.8M=8MB (64Mb)
vintlabs-devkit-v1.menu.FlashSize.8M.build.flash_size=8MB
vintlabs-devkit-v1.menu.FlashSize.8M.build.partitions=default_8MB
vintlabs-devkit-v1.menu.FlashSize.2M=2MB (16Mb)
vintlabs-devkit-v1.menu.FlashSize.2M.build.flash_size=2MB
vintlabs-devkit-v1.menu.FlashSize.2M.build.partitions=minimal
vintlabs-devkit-v1.menu.FlashSize.16M=16MB (128Mb)
vintlabs-devkit-v1.menu.FlashSize.16M.build.flash_size=16MB
vintlabs-devkit-v1.menu.DebugLevel.none=None
vintlabs-devkit-v1.menu.DebugLevel.none.build.code_debug=0
vintlabs-devkit-v1.menu.DebugLevel.error=Error
@ -4202,3 +4324,453 @@ vintlabs-devkit-v1.menu.DebugLevel.debug.build.code_debug=4
##############################################################
honeylemon.name=HONEYLemon
honeylemon.upload.tool=esptool_py
honeylemon.upload.maximum_size=1310720
honeylemon.upload.maximum_data_size=327680
honeylemon.upload.wait_for_upload_port=true
honeylemon.serial.disableDTR=true
honeylemon.serial.disableRTS=true
honeylemon.build.mcu=esp32
honeylemon.build.core=esp32
honeylemon.build.variant=honeylemon
honeylemon.build.board=HONEYLEMON
honeylemon.build.f_cpu=240000000L
honeylemon.build.flash_mode=dio
honeylemon.build.flash_size=4MB
honeylemon.build.boot=dio
honeylemon.build.partitions=default
honeylemon.build.defines=
honeylemon.menu.FlashFreq.80=80MHz
honeylemon.menu.FlashFreq.80.build.flash_freq=80m
honeylemon.menu.FlashFreq.40=40MHz
honeylemon.menu.FlashFreq.40.build.flash_freq=40m
honeylemon.menu.UploadSpeed.921600=921600
honeylemon.menu.UploadSpeed.921600.upload.speed=921600
honeylemon.menu.UploadSpeed.115200=115200
honeylemon.menu.UploadSpeed.115200.upload.speed=115200
honeylemon.menu.UploadSpeed.256000.windows=256000
honeylemon.menu.UploadSpeed.256000.upload.speed=256000
honeylemon.menu.UploadSpeed.230400.windows.upload.speed=256000
honeylemon.menu.UploadSpeed.230400=230400
honeylemon.menu.UploadSpeed.230400.upload.speed=230400
honeylemon.menu.UploadSpeed.460800.linux=460800
honeylemon.menu.UploadSpeed.460800.macosx=460800
honeylemon.menu.UploadSpeed.460800.upload.speed=460800
honeylemon.menu.UploadSpeed.512000.windows=512000
honeylemon.menu.UploadSpeed.512000.upload.speed=512000
##############################################################
mgbot-iotik32a.name=MGBOT IOTIK 32A
mgbot-iotik32a.upload.tool=esptool_py
mgbot-iotik32a.upload.maximum_size=1310720
mgbot-iotik32a.upload.maximum_data_size=327680
mgbot-iotik32a.upload.wait_for_upload_port=true
mgbot-iotik32a.serial.disableDTR=true
mgbot-iotik32a.serial.disableRTS=true
mgbot-iotik32a.build.mcu=esp32
mgbot-iotik32a.build.core=esp32
mgbot-iotik32a.build.variant=mgbot-iotik32a
mgbot-iotik32a.build.board=MGBOT_IOTIK32A
mgbot-iotik32a.build.f_cpu=240000000L
mgbot-iotik32a.build.flash_size=4MB
mgbot-iotik32a.build.flash_freq=40m
mgbot-iotik32a.build.flash_mode=dio
mgbot-iotik32a.build.boot=dio
mgbot-iotik32a.build.partitions=default
mgbot-iotik32a.build.defines=
mgbot-iotik32a.menu.PSRAM.disabled=Disabled
mgbot-iotik32a.menu.PSRAM.disabled.build.defines=
mgbot-iotik32a.menu.PSRAM.enabled=Enabled
mgbot-iotik32a.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue
mgbot-iotik32a.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
mgbot-iotik32a.menu.PartitionScheme.default.build.partitions=default
mgbot-iotik32a.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS)
mgbot-iotik32a.menu.PartitionScheme.defaultffat.build.partitions=default_ffat
mgbot-iotik32a.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT)
mgbot-iotik32a.menu.PartitionScheme.default_8MB.build.partitions=default_8MB
mgbot-iotik32a.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336
mgbot-iotik32a.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS)
mgbot-iotik32a.menu.PartitionScheme.minimal.build.partitions=minimal
mgbot-iotik32a.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS)
mgbot-iotik32a.menu.PartitionScheme.no_ota.build.partitions=no_ota
mgbot-iotik32a.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
mgbot-iotik32a.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS)
mgbot-iotik32a.menu.PartitionScheme.noota_3g.build.partitions=noota_3g
mgbot-iotik32a.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576
mgbot-iotik32a.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS)
mgbot-iotik32a.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat
mgbot-iotik32a.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152
mgbot-iotik32a.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS)
mgbot-iotik32a.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat
mgbot-iotik32a.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576
mgbot-iotik32a.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS)
mgbot-iotik32a.menu.PartitionScheme.huge_app.build.partitions=huge_app
mgbot-iotik32a.menu.PartitionScheme.huge_app.upload.maximum_size=3145728
mgbot-iotik32a.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)
mgbot-iotik32a.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
mgbot-iotik32a.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
mgbot-iotik32a.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT)
mgbot-iotik32a.menu.PartitionScheme.fatflash.build.partitions=ffat
mgbot-iotik32a.menu.PartitionScheme.fatflash.upload.maximum_size=2097152
mgbot-iotik32a.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS)
mgbot-iotik32a.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB
mgbot-iotik32a.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728
mgbot-iotik32a.menu.CPUFreq.240=240MHz (WiFi/BT)
mgbot-iotik32a.menu.CPUFreq.240.build.f_cpu=240000000L
mgbot-iotik32a.menu.CPUFreq.160=160MHz (WiFi/BT)
mgbot-iotik32a.menu.CPUFreq.160.build.f_cpu=160000000L
mgbot-iotik32a.menu.CPUFreq.80=80MHz (WiFi/BT)
mgbot-iotik32a.menu.CPUFreq.80.build.f_cpu=80000000L
mgbot-iotik32a.menu.CPUFreq.40=40MHz (40MHz XTAL)
mgbot-iotik32a.menu.CPUFreq.40.build.f_cpu=40000000L
mgbot-iotik32a.menu.CPUFreq.26=26MHz (26MHz XTAL)
mgbot-iotik32a.menu.CPUFreq.26.build.f_cpu=26000000L
mgbot-iotik32a.menu.CPUFreq.20=20MHz (40MHz XTAL)
mgbot-iotik32a.menu.CPUFreq.20.build.f_cpu=20000000L
mgbot-iotik32a.menu.CPUFreq.13=13MHz (26MHz XTAL)
mgbot-iotik32a.menu.CPUFreq.13.build.f_cpu=13000000L
mgbot-iotik32a.menu.CPUFreq.10=10MHz (40MHz XTAL)
mgbot-iotik32a.menu.CPUFreq.10.build.f_cpu=10000000L
mgbot-iotik32a.menu.FlashMode.qio=QIO
mgbot-iotik32a.menu.FlashMode.qio.build.flash_mode=dio
mgbot-iotik32a.menu.FlashMode.qio.build.boot=qio
mgbot-iotik32a.menu.FlashMode.dio=DIO
mgbot-iotik32a.menu.FlashMode.dio.build.flash_mode=dio
mgbot-iotik32a.menu.FlashMode.dio.build.boot=dio
mgbot-iotik32a.menu.FlashMode.qout=QOUT
mgbot-iotik32a.menu.FlashMode.qout.build.flash_mode=dout
mgbot-iotik32a.menu.FlashMode.qout.build.boot=qout
mgbot-iotik32a.menu.FlashMode.dout=DOUT
mgbot-iotik32a.menu.FlashMode.dout.build.flash_mode=dout
mgbot-iotik32a.menu.FlashMode.dout.build.boot=dout
mgbot-iotik32a.menu.FlashFreq.80=80MHz
mgbot-iotik32a.menu.FlashFreq.80.build.flash_freq=80m
mgbot-iotik32a.menu.FlashFreq.40=40MHz
mgbot-iotik32a.menu.FlashFreq.40.build.flash_freq=40m
mgbot-iotik32a.menu.FlashSize.4M=4MB (32Mb)
mgbot-iotik32a.menu.FlashSize.4M.build.flash_size=4MB
mgbot-iotik32a.menu.FlashSize.8M=8MB (64Mb)
mgbot-iotik32a.menu.FlashSize.8M.build.flash_size=8MB
mgbot-iotik32a.menu.FlashSize.8M.build.partitions=default_8MB
mgbot-iotik32a.menu.FlashSize.2M=2MB (16Mb)
mgbot-iotik32a.menu.FlashSize.2M.build.flash_size=2MB
mgbot-iotik32a.menu.FlashSize.2M.build.partitions=minimal
mgbot-iotik32a.menu.FlashSize.16M=16MB (128Mb)
mgbot-iotik32a.menu.FlashSize.16M.build.flash_size=16MB
mgbot-iotik32a.menu.UploadSpeed.921600=921600
mgbot-iotik32a.menu.UploadSpeed.921600.upload.speed=921600
mgbot-iotik32a.menu.UploadSpeed.115200=115200
mgbot-iotik32a.menu.UploadSpeed.115200.upload.speed=115200
mgbot-iotik32a.menu.UploadSpeed.256000.windows=256000
mgbot-iotik32a.menu.UploadSpeed.256000.upload.speed=256000
mgbot-iotik32a.menu.UploadSpeed.230400.windows.upload.speed=256000
mgbot-iotik32a.menu.UploadSpeed.230400=230400
mgbot-iotik32a.menu.UploadSpeed.230400.upload.speed=230400
mgbot-iotik32a.menu.UploadSpeed.460800.linux=460800
mgbot-iotik32a.menu.UploadSpeed.460800.macosx=460800
mgbot-iotik32a.menu.UploadSpeed.460800.upload.speed=460800
mgbot-iotik32a.menu.UploadSpeed.512000.windows=512000
mgbot-iotik32a.menu.UploadSpeed.512000.upload.speed=512000
mgbot-iotik32a.menu.DebugLevel.none=None
mgbot-iotik32a.menu.DebugLevel.none.build.code_debug=0
mgbot-iotik32a.menu.DebugLevel.error=Error
mgbot-iotik32a.menu.DebugLevel.error.build.code_debug=1
mgbot-iotik32a.menu.DebugLevel.warn=Warn
mgbot-iotik32a.menu.DebugLevel.warn.build.code_debug=2
mgbot-iotik32a.menu.DebugLevel.info=Info
mgbot-iotik32a.menu.DebugLevel.info.build.code_debug=3
mgbot-iotik32a.menu.DebugLevel.debug=Debug
mgbot-iotik32a.menu.DebugLevel.debug.build.code_debug=4
mgbot-iotik32a.menu.DebugLevel.verbose=Verbose
mgbot-iotik32a.menu.DebugLevel.verbose.build.code_debug=5
##############################################################
mgbot-iotik32b.name=MGBOT IOTIK 32B
mgbot-iotik32b.upload.tool=esptool_py
mgbot-iotik32b.upload.maximum_size=1310720
mgbot-iotik32b.upload.maximum_data_size=327680
mgbot-iotik32b.upload.wait_for_upload_port=true
mgbot-iotik32b.serial.disableDTR=true
mgbot-iotik32b.serial.disableRTS=true
mgbot-iotik32b.build.mcu=esp32
mgbot-iotik32b.build.core=esp32
mgbot-iotik32b.build.variant=mgbot-iotik32b
mgbot-iotik32b.build.board=MGBOT_IOTIK32B
mgbot-iotik32b.build.f_cpu=240000000L
mgbot-iotik32b.build.flash_size=4MB
mgbot-iotik32b.build.flash_freq=40m
mgbot-iotik32b.build.flash_mode=dio
mgbot-iotik32b.build.boot=dio
mgbot-iotik32b.build.partitions=default
mgbot-iotik32b.build.defines=
mgbot-iotik32b.menu.PSRAM.disabled=Disabled
mgbot-iotik32b.menu.PSRAM.disabled.build.defines=
mgbot-iotik32b.menu.PSRAM.enabled=Enabled
mgbot-iotik32b.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue
mgbot-iotik32b.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
mgbot-iotik32b.menu.PartitionScheme.default.build.partitions=default
mgbot-iotik32b.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS)
mgbot-iotik32b.menu.PartitionScheme.defaultffat.build.partitions=default_ffat
mgbot-iotik32b.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT)
mgbot-iotik32b.menu.PartitionScheme.default_8MB.build.partitions=default_8MB
mgbot-iotik32b.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336
mgbot-iotik32b.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS)
mgbot-iotik32b.menu.PartitionScheme.minimal.build.partitions=minimal
mgbot-iotik32b.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS)
mgbot-iotik32b.menu.PartitionScheme.no_ota.build.partitions=no_ota
mgbot-iotik32b.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
mgbot-iotik32b.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS)
mgbot-iotik32b.menu.PartitionScheme.noota_3g.build.partitions=noota_3g
mgbot-iotik32b.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576
mgbot-iotik32b.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS)
mgbot-iotik32b.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat
mgbot-iotik32b.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152
mgbot-iotik32b.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS)
mgbot-iotik32b.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat
mgbot-iotik32b.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576
mgbot-iotik32b.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS)
mgbot-iotik32b.menu.PartitionScheme.huge_app.build.partitions=huge_app
mgbot-iotik32b.menu.PartitionScheme.huge_app.upload.maximum_size=3145728
mgbot-iotik32b.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)
mgbot-iotik32b.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
mgbot-iotik32b.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
mgbot-iotik32b.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT)
mgbot-iotik32b.menu.PartitionScheme.fatflash.build.partitions=ffat
mgbot-iotik32b.menu.PartitionScheme.fatflash.upload.maximum_size=2097152
mgbot-iotik32b.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS)
mgbot-iotik32b.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB
mgbot-iotik32b.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728
mgbot-iotik32b.menu.CPUFreq.240=240MHz (WiFi/BT)
mgbot-iotik32b.menu.CPUFreq.240.build.f_cpu=240000000L
mgbot-iotik32b.menu.CPUFreq.160=160MHz (WiFi/BT)
mgbot-iotik32b.menu.CPUFreq.160.build.f_cpu=160000000L
mgbot-iotik32b.menu.CPUFreq.80=80MHz (WiFi/BT)
mgbot-iotik32b.menu.CPUFreq.80.build.f_cpu=80000000L
mgbot-iotik32b.menu.CPUFreq.40=40MHz (40MHz XTAL)
mgbot-iotik32b.menu.CPUFreq.40.build.f_cpu=40000000L
mgbot-iotik32b.menu.CPUFreq.26=26MHz (26MHz XTAL)
mgbot-iotik32b.menu.CPUFreq.26.build.f_cpu=26000000L
mgbot-iotik32b.menu.CPUFreq.20=20MHz (40MHz XTAL)
mgbot-iotik32b.menu.CPUFreq.20.build.f_cpu=20000000L
mgbot-iotik32b.menu.CPUFreq.13=13MHz (26MHz XTAL)
mgbot-iotik32b.menu.CPUFreq.13.build.f_cpu=13000000L
mgbot-iotik32b.menu.CPUFreq.10=10MHz (40MHz XTAL)
mgbot-iotik32b.menu.CPUFreq.10.build.f_cpu=10000000L
mgbot-iotik32b.menu.FlashMode.qio=QIO
mgbot-iotik32b.menu.FlashMode.qio.build.flash_mode=dio
mgbot-iotik32b.menu.FlashMode.qio.build.boot=qio
mgbot-iotik32b.menu.FlashMode.dio=DIO
mgbot-iotik32b.menu.FlashMode.dio.build.flash_mode=dio
mgbot-iotik32b.menu.FlashMode.dio.build.boot=dio
mgbot-iotik32b.menu.FlashMode.qout=QOUT
mgbot-iotik32b.menu.FlashMode.qout.build.flash_mode=dout
mgbot-iotik32b.menu.FlashMode.qout.build.boot=qout
mgbot-iotik32b.menu.FlashMode.dout=DOUT
mgbot-iotik32b.menu.FlashMode.dout.build.flash_mode=dout
mgbot-iotik32b.menu.FlashMode.dout.build.boot=dout
mgbot-iotik32b.menu.FlashFreq.80=80MHz
mgbot-iotik32b.menu.FlashFreq.80.build.flash_freq=80m
mgbot-iotik32b.menu.FlashFreq.40=40MHz
mgbot-iotik32b.menu.FlashFreq.40.build.flash_freq=40m
mgbot-iotik32b.menu.FlashSize.4M=4MB (32Mb)
mgbot-iotik32b.menu.FlashSize.4M.build.flash_size=4MB
mgbot-iotik32b.menu.FlashSize.8M=8MB (64Mb)
mgbot-iotik32b.menu.FlashSize.8M.build.flash_size=8MB
mgbot-iotik32b.menu.FlashSize.8M.build.partitions=default_8MB
mgbot-iotik32b.menu.FlashSize.2M=2MB (16Mb)
mgbot-iotik32b.menu.FlashSize.2M.build.flash_size=2MB
mgbot-iotik32b.menu.FlashSize.2M.build.partitions=minimal
mgbot-iotik32b.menu.FlashSize.16M=16MB (128Mb)
mgbot-iotik32b.menu.FlashSize.16M.build.flash_size=16MB
mgbot-iotik32b.menu.UploadSpeed.921600=921600
mgbot-iotik32b.menu.UploadSpeed.921600.upload.speed=921600
mgbot-iotik32b.menu.UploadSpeed.115200=115200
mgbot-iotik32b.menu.UploadSpeed.115200.upload.speed=115200
mgbot-iotik32b.menu.UploadSpeed.256000.windows=256000
mgbot-iotik32b.menu.UploadSpeed.256000.upload.speed=256000
mgbot-iotik32b.menu.UploadSpeed.230400.windows.upload.speed=256000
mgbot-iotik32b.menu.UploadSpeed.230400=230400
mgbot-iotik32b.menu.UploadSpeed.230400.upload.speed=230400
mgbot-iotik32b.menu.UploadSpeed.460800.linux=460800
mgbot-iotik32b.menu.UploadSpeed.460800.macosx=460800
mgbot-iotik32b.menu.UploadSpeed.460800.upload.speed=460800
mgbot-iotik32b.menu.UploadSpeed.512000.windows=512000
mgbot-iotik32b.menu.UploadSpeed.512000.upload.speed=512000
mgbot-iotik32b.menu.DebugLevel.none=None
mgbot-iotik32b.menu.DebugLevel.none.build.code_debug=0
mgbot-iotik32b.menu.DebugLevel.error=Error
mgbot-iotik32b.menu.DebugLevel.error.build.code_debug=1
mgbot-iotik32b.menu.DebugLevel.warn=Warn
mgbot-iotik32b.menu.DebugLevel.warn.build.code_debug=2
mgbot-iotik32b.menu.DebugLevel.info=Info
mgbot-iotik32b.menu.DebugLevel.info.build.code_debug=3
mgbot-iotik32b.menu.DebugLevel.debug=Debug
mgbot-iotik32b.menu.DebugLevel.debug.build.code_debug=4
mgbot-iotik32b.menu.DebugLevel.verbose=Verbose
mgbot-iotik32b.menu.DebugLevel.verbose.build.code_debug=5
##############################################################
piranha_esp-32.name=Piranha ESP-32
piranha_esp-32.upload.tool=esptool_py
piranha_esp-32.upload.maximum_size=1310720
piranha_esp-32.upload.maximum_data_size=327680
piranha_esp-32.upload.wait_for_upload_port=true
piranha_esp-32.serial.disableDTR=true
piranha_esp-32.serial.disableRTS=true
piranha_esp-32.build.mcu=esp32
piranha_esp-32.build.core=esp32
piranha_esp-32.build.variant=piranha_esp-32
piranha_esp-32.build.board=Piranha
piranha_esp-32.build.f_cpu=240000000L
piranha_esp-32.build.flash_mode=dio
piranha_esp-32.build.flash_size=4MB
piranha_esp-32.build.boot=dio
piranha_esp-32.build.partitions=default
piranha_esp-32.build.defines=
piranha_esp-32.menu.PartitionScheme.default=Default
piranha_esp-32.menu.PartitionScheme.default.build.partitions=default
piranha_esp-32.menu.PartitionScheme.no_ota=No OTA (Large APP)
piranha_esp-32.menu.PartitionScheme.no_ota.build.partitions=no_ota
piranha_esp-32.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
piranha_esp-32.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
piranha_esp-32.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
piranha_esp-32.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
piranha_esp-32.menu.FlashFreq.80=80MHz
piranha_esp-32.menu.FlashFreq.80.build.flash_freq=80m
piranha_esp-32.menu.FlashFreq.40=40MHz
piranha_esp-32.menu.FlashFreq.40.build.flash_freq=40m
piranha_esp-32.menu.UploadSpeed.921600=921600
piranha_esp-32.menu.UploadSpeed.921600.upload.speed=921600
piranha_esp-32.menu.UploadSpeed.115200=115200
piranha_esp-32.menu.UploadSpeed.115200.upload.speed=115200
piranha_esp-32.menu.UploadSpeed.256000.windows=256000
piranha_esp-32.menu.UploadSpeed.256000.upload.speed=256000
piranha_esp-32.menu.UploadSpeed.230400.windows.upload.speed=256000
piranha_esp-32.menu.UploadSpeed.230400=230400
piranha_esp-32.menu.UploadSpeed.230400.upload.speed=230400
piranha_esp-32.menu.UploadSpeed.460800.linux=460800
piranha_esp-32.menu.UploadSpeed.460800.macosx=460800
piranha_esp-32.menu.UploadSpeed.460800.upload.speed=460800
piranha_esp-32.menu.UploadSpeed.512000.windows=512000
piranha_esp-32.menu.UploadSpeed.512000.upload.speed=512000
piranha_esp-32.menu.DebugLevel.none=None
piranha_esp-32.menu.DebugLevel.none.build.code_debug=0
piranha_esp-32.menu.DebugLevel.error=Error
piranha_esp-32.menu.DebugLevel.error.build.code_debug=1
piranha_esp-32.menu.DebugLevel.warn=Warn
piranha_esp-32.menu.DebugLevel.warn.build.code_debug=2
piranha_esp-32.menu.DebugLevel.info=Info
piranha_esp-32.menu.DebugLevel.info.build.code_debug=3
piranha_esp-32.menu.DebugLevel.debug=Debug
piranha_esp-32.menu.DebugLevel.debug.build.code_debug=4
piranha_esp-32.menu.DebugLevel.verbose=Verbose
piranha_esp-32.menu.DebugLevel.verbose.build.code_debug=5
##############################################################
metro_esp-32.name=Metro ESP-32
metro_esp-32.upload.tool=esptool_py
metro_esp-32.upload.maximum_size=1310720
metro_esp-32.upload.maximum_data_size=327680
metro_esp-32.upload.wait_for_upload_port=true
metro_esp-32.serial.disableDTR=true
metro_esp-32.serial.disableRTS=true
metro_esp-32.build.mcu=esp32
metro_esp-32.build.core=esp32
metro_esp-32.build.variant=metro_esp-32
metro_esp-32.build.board=Metro
metro_esp-32.build.f_cpu=240000000L
metro_esp-32.build.flash_mode=dio
metro_esp-32.build.flash_size=4MB
metro_esp-32.build.boot=dio
metro_esp-32.build.partitions=default
metro_esp-32.build.defines=
metro_esp-32.menu.PartitionScheme.default=Default
metro_esp-32.menu.PartitionScheme.default.build.partitions=default
metro_esp-32.menu.PartitionScheme.no_ota=No OTA (Large APP)
metro_esp-32.menu.PartitionScheme.no_ota.build.partitions=no_ota
metro_esp-32.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
metro_esp-32.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
metro_esp-32.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
metro_esp-32.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
metro_esp-32.menu.FlashFreq.80=80MHz
metro_esp-32.menu.FlashFreq.80.build.flash_freq=80m
metro_esp-32.menu.FlashFreq.40=40MHz
metro_esp-32.menu.FlashFreq.40.build.flash_freq=40m
metro_esp-32.menu.UploadSpeed.921600=921600
metro_esp-32.menu.UploadSpeed.921600.upload.speed=921600
metro_esp-32.menu.UploadSpeed.115200=115200
metro_esp-32.menu.UploadSpeed.115200.upload.speed=115200
metro_esp-32.menu.UploadSpeed.256000.windows=256000
metro_esp-32.menu.UploadSpeed.256000.upload.speed=256000
metro_esp-32.menu.UploadSpeed.230400.windows.upload.speed=256000
metro_esp-32.menu.UploadSpeed.230400=230400
metro_esp-32.menu.UploadSpeed.230400.upload.speed=230400
metro_esp-32.menu.UploadSpeed.460800.linux=460800
metro_esp-32.menu.UploadSpeed.460800.macosx=460800
metro_esp-32.menu.UploadSpeed.460800.upload.speed=460800
metro_esp-32.menu.UploadSpeed.512000.windows=512000
metro_esp-32.menu.UploadSpeed.512000.upload.speed=512000
metro_esp-32.menu.DebugLevel.none=None
metro_esp-32.menu.DebugLevel.none.build.code_debug=0
metro_esp-32.menu.DebugLevel.error=Error
metro_esp-32.menu.DebugLevel.error.build.code_debug=1
metro_esp-32.menu.DebugLevel.warn=Warn
metro_esp-32.menu.DebugLevel.warn.build.code_debug=2
metro_esp-32.menu.DebugLevel.info=Info
metro_esp-32.menu.DebugLevel.info.build.code_debug=3
metro_esp-32.menu.DebugLevel.debug=Debug
metro_esp-32.menu.DebugLevel.debug.build.code_debug=4
metro_esp-32.menu.DebugLevel.verbose=Verbose
metro_esp-32.menu.DebugLevel.verbose.build.code_debug=5
##############################################################

View File

@ -118,7 +118,9 @@ typedef unsigned int word;
void setup(void);
void loop(void);
#ifdef __cplusplus
long random(long, long);
#endif
void randomSeed(unsigned long);
long map(long, long, long, long, long);

View File

@ -19,7 +19,6 @@
#include "Arduino.h"
#include "Esp.h"
#include "rom/spi_flash.h"
#include "esp_sleep.h"
#include "esp_spi_flash.h"
#include <memory>
@ -32,6 +31,17 @@ extern "C" {
}
#include <MD5Builder.h>
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/spi_flash.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/spi_flash.h"
#endif
/**
* User-defined Literals
* usage:

View File

@ -131,11 +131,34 @@ int HardwareSerial::read(void)
return -1;
}
void HardwareSerial::flush()
// read characters into buffer
// terminates if size characters have been read, or no further are pending
// returns the number of characters placed in the buffer
// the buffer is NOT null terminated.
size_t HardwareSerial::read(uint8_t *buffer, size_t size)
{
size_t avail = available();
if (size < avail) {
avail = size;
}
size_t count = 0;
while(count < avail) {
*buffer++ = uartRead(_uart);
count++;
}
return count;
}
void HardwareSerial::flush(void)
{
uartFlush(_uart);
}
void HardwareSerial::flush(bool txOnly)
{
uartFlushTxOnly(_uart, txOnly);
}
size_t HardwareSerial::write(uint8_t c)
{
uartWrite(_uart, c);

View File

@ -62,10 +62,19 @@ public:
int availableForWrite(void);
int peek(void);
int read(void);
size_t read(uint8_t *buffer, size_t size);
inline size_t read(char * buffer, size_t size)
{
return read((uint8_t*) buffer, size);
}
void flush(void);
void flush( bool txOnly);
size_t write(uint8_t);
size_t write(const uint8_t *buffer, size_t size);
inline size_t write(const char * buffer, size_t size)
{
return write((uint8_t*) buffer, size);
}
inline size_t write(const char * s)
{
return write((uint8_t*) s, strlen(s));
@ -97,10 +106,12 @@ protected:
uart_t* _uart;
};
extern void serialEventRun(void) __attribute__((weak));
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
extern HardwareSerial Serial;
extern HardwareSerial Serial1;
extern HardwareSerial Serial2;
#endif
#endif
#endif // HardwareSerial_h

View File

@ -21,7 +21,17 @@
#include <WString.h>
#include <Stream.h>
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/md5_hash.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/md5_hash.h"
#endif
class MD5Builder
{

View File

@ -203,8 +203,20 @@ class String {
unsigned char equalsIgnoreCase(const String &s) const;
unsigned char equalsConstantTime(const String &s) const;
unsigned char startsWith(const String &prefix) const;
unsigned char startsWith(const char *prefix) const {
return this->startsWith(String(prefix));
}
unsigned char startsWith(const __FlashStringHelper *prefix) const {
return this->startsWith(String(prefix));
}
unsigned char startsWith(const String &prefix, unsigned int offset) const;
unsigned char endsWith(const String &suffix) const;
unsigned char endsWith(const char *suffix) const {
return this->endsWith(String(suffix));
}
unsigned char endsWith(const __FlashStringHelper * suffix) const {
return this->endsWith(String(suffix));
}
// character access
char charAt(unsigned int index) const;
@ -238,7 +250,22 @@ class String {
// modification
void replace(char find, char replace);
void replace(const String& find, const String& replace);
void replace(const String &find, const String &replace);
void replace(const char *find, const String &replace) {
this->replace(String(find), replace);
}
void replace(const __FlashStringHelper *find, const String &replace) {
this->replace(String(find), replace);
}
void replace(const char *find, const char *replace) {
this->replace(String(find), String(replace));
}
void replace(const __FlashStringHelper *find, const char *replace) {
this->replace(String(find), String(replace));
}
void replace(const __FlashStringHelper *find, const __FlashStringHelper *replace) {
this->replace(String(find), String(replace));
}
void remove(unsigned int index);
void remove(unsigned int index, unsigned int count);
void toLowerCase(void);

View File

@ -31,11 +31,11 @@ extern "C" {
/**
* convert input data to base64
* @param data uint8_t *
* @param data const uint8_t *
* @param length size_t
* @return String
*/
String base64::encode(uint8_t * data, size_t length)
String base64::encode(const uint8_t * data, size_t length)
{
size_t size = base64_encode_expected_len(length) + 1;
char * buffer = (char *) malloc(size);
@ -54,10 +54,10 @@ String base64::encode(uint8_t * data, size_t length)
/**
* convert input data to base64
* @param text String
* @param text const String&
* @return String
*/
String base64::encode(String text)
String base64::encode(const String& text)
{
return base64::encode((uint8_t *) text.c_str(), text.length());
}

View File

@ -4,8 +4,8 @@
class base64
{
public:
static String encode(uint8_t * data, size_t length);
static String encode(String text);
static String encode(const uint8_t * data, size_t length);
static String encode(const String& text);
private:
};

View File

@ -15,21 +15,34 @@
#include "esp32-hal-adc.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "rom/ets_sys.h"
#include "esp_attr.h"
#include "esp_intr.h"
#include "soc/rtc_io_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/sens_reg.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#include "esp_intr_alloc.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#include "esp_intr.h"
#endif
#define DEFAULT_VREF 1100
static esp_adc_cal_characteristics_t *__analogCharacteristics[2] = {NULL, NULL};
static uint8_t __analogAttenuation = 3;//11db
static uint8_t __analogWidth = 3;//12 bits
static uint8_t __analogCycles = 8;
static uint8_t __analogSamples = 0;//1 sample
static uint8_t __analogClockDiv = 1;
// Width of returned answer ()
static uint8_t __analogReturnedWidth = 12;
static uint16_t __analogVRef = 0;
static uint8_t __analogVRefPin = 0;
void __analogSetWidth(uint8_t bits){
if(bits < 9){
@ -37,81 +50,31 @@ void __analogSetWidth(uint8_t bits){
} else if(bits > 12){
bits = 12;
}
__analogReturnedWidth = bits;
__analogWidth = bits - 9;
SET_PERI_REG_BITS(SENS_SAR_START_FORCE_REG, SENS_SAR1_BIT_WIDTH, __analogWidth, SENS_SAR1_BIT_WIDTH_S);
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_SAMPLE_BIT, __analogWidth, SENS_SAR1_SAMPLE_BIT_S);
SET_PERI_REG_BITS(SENS_SAR_START_FORCE_REG, SENS_SAR2_BIT_WIDTH, __analogWidth, SENS_SAR2_BIT_WIDTH_S);
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_SAMPLE_BIT, __analogWidth, SENS_SAR2_SAMPLE_BIT_S);
}
void __analogSetCycles(uint8_t cycles){
__analogCycles = cycles;
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_SAMPLE_CYCLE, __analogCycles, SENS_SAR1_SAMPLE_CYCLE_S);
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_SAMPLE_CYCLE, __analogCycles, SENS_SAR2_SAMPLE_CYCLE_S);
}
void __analogSetSamples(uint8_t samples){
if(!samples){
return;
}
__analogSamples = samples - 1;
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_SAMPLE_NUM, __analogSamples, SENS_SAR1_SAMPLE_NUM_S);
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_SAMPLE_NUM, __analogSamples, SENS_SAR2_SAMPLE_NUM_S);
adc1_config_width(__analogWidth);
}
void __analogSetClockDiv(uint8_t clockDiv){
if(!clockDiv){
return;
clockDiv = 1;
}
__analogClockDiv = clockDiv;
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_CLK_DIV, __analogClockDiv, SENS_SAR1_CLK_DIV_S);
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_CLK_DIV, __analogClockDiv, SENS_SAR2_CLK_DIV_S);
adc_set_clk_div(__analogClockDiv);
}
void __analogSetAttenuation(adc_attenuation_t attenuation)
{
__analogAttenuation = attenuation & 3;
uint32_t att_data = 0;
int i = 10;
while(i--){
att_data |= __analogAttenuation << (i * 2);
}
WRITE_PERI_REG(SENS_SAR_ATTEN1_REG, att_data & 0xFFFF);//ADC1 has 8 channels
WRITE_PERI_REG(SENS_SAR_ATTEN2_REG, att_data);
}
void IRAM_ATTR __analogInit(){
void __analogInit(){
static bool initialized = false;
if(initialized){
return;
}
__analogSetAttenuation(__analogAttenuation);
__analogSetCycles(__analogCycles);
__analogSetSamples(__analogSamples + 1);//in samples
initialized = true;
__analogSetClockDiv(__analogClockDiv);
__analogSetWidth(__analogWidth + 9);//in bits
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DATA_INV);
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DATA_INV);
SET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_FORCE_M); //SAR ADC1 controller (in RTC) is started by SW
SET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD_FORCE_M); //SAR ADC1 pad enable bitmap is controlled by SW
SET_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_FORCE_M); //SAR ADC2 controller (in RTC) is started by SW
SET_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_SAR2_EN_PAD_FORCE_M); //SAR ADC2 pad enable bitmap is controlled by SW
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR_M); //force XPD_SAR=0, use XPD_FSM
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_AMP, 0x2, SENS_FORCE_XPD_AMP_S); //force XPD_AMP=0
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_CTRL_REG, 0xfff << SENS_AMP_RST_FB_FSM_S); //clear FSM
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT1_REG, SENS_SAR_AMP_WAIT1, 0x1, SENS_SAR_AMP_WAIT1_S);
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT1_REG, SENS_SAR_AMP_WAIT2, 0x1, SENS_SAR_AMP_WAIT2_S);
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_SAR_AMP_WAIT3, 0x1, SENS_SAR_AMP_WAIT3_S);
while (GET_PERI_REG_BITS2(SENS_SAR_SLAVE_ADDR1_REG, 0x7, SENS_MEAS_STATUS_S) != 0); //wait det_fsm==
initialized = true;
}
void __analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation)
@ -120,21 +83,20 @@ void __analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation)
if(channel < 0 || attenuation > 3){
return ;
}
__analogInit();
if(channel > 7){
SET_PERI_REG_BITS(SENS_SAR_ATTEN2_REG, 3, attenuation, ((channel - 10) * 2));
if(channel > 9){
adc2_config_channel_atten(channel - 10, attenuation);
} else {
SET_PERI_REG_BITS(SENS_SAR_ATTEN1_REG, 3, attenuation, (channel * 2));
adc1_config_channel_atten(channel, attenuation);
}
__analogInit();
}
bool IRAM_ATTR __adcAttachPin(uint8_t pin){
bool __adcAttachPin(uint8_t pin){
int8_t channel = digitalPinToAnalogChannel(pin);
if(channel < 0){
return false;//not adc pin
log_e("Pin %u is not ADC pin!", pin);
return false;
}
int8_t pad = digitalPinToTouchChannel(pin);
if(pad >= 0){
uint32_t touch = READ_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG);
@ -151,86 +113,103 @@ bool IRAM_ATTR __adcAttachPin(uint8_t pin){
}
pinMode(pin, ANALOG);
__analogInit();
__analogSetPinAttenuation(pin, __analogAttenuation);
return true;
}
bool IRAM_ATTR __adcStart(uint8_t pin){
int8_t channel = digitalPinToAnalogChannel(pin);
if(channel < 0){
return false;//not adc pin
}
if(channel > 9){
channel -= 10;
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_SAR_M);
SET_PERI_REG_BITS(SENS_SAR_MEAS_START2_REG, SENS_SAR2_EN_PAD, (1 << channel), SENS_SAR2_EN_PAD_S);
SET_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_SAR_M);
} else {
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M);
SET_PERI_REG_BITS(SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD, (1 << channel), SENS_SAR1_EN_PAD_S);
SET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M);
}
return true;
}
bool IRAM_ATTR __adcBusy(uint8_t pin){
int8_t channel = digitalPinToAnalogChannel(pin);
if(channel < 0){
return false;//not adc pin
}
if(channel > 7){
return (GET_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_DONE_SAR) == 0);
}
return (GET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DONE_SAR) == 0);
}
uint16_t IRAM_ATTR __adcEnd(uint8_t pin)
{
uint16_t value = 0;
int8_t channel = digitalPinToAnalogChannel(pin);
if(channel < 0){
return 0;//not adc pin
}
if(channel > 7){
while (GET_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_DONE_SAR) == 0); //wait for conversion
value = GET_PERI_REG_BITS2(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_DATA_SAR, SENS_MEAS2_DATA_SAR_S);
} else {
while (GET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DONE_SAR) == 0); //wait for conversion
value = GET_PERI_REG_BITS2(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DATA_SAR, SENS_MEAS1_DATA_SAR_S);
}
// Shift result if necessary
uint8_t from = __analogWidth + 9;
if (from == __analogReturnedWidth) {
return value;
}
if (from > __analogReturnedWidth) {
return value >> (from - __analogReturnedWidth);
}
return value << (__analogReturnedWidth - from);
}
uint16_t IRAM_ATTR __analogRead(uint8_t pin)
{
if(!__adcAttachPin(pin) || !__adcStart(pin)){
return 0;
}
return __adcEnd(pin);
}
void __analogReadResolution(uint8_t bits)
{
if(!bits || bits > 16){
return;
}
__analogSetWidth(bits); // hadware from 9 to 12
__analogReturnedWidth = bits; // software from 1 to 16
}
uint16_t __analogRead(uint8_t pin)
{
int8_t channel = digitalPinToAnalogChannel(pin);
int value = 0;
esp_err_t r = ESP_OK;
if(channel < 0){
log_e("Pin %u is not ADC pin!", pin);
return value;
}
__adcAttachPin(pin);
if(channel > 9){
channel -= 10;
r = adc2_get_raw( channel, __analogWidth, &value);
if ( r == ESP_OK ) {
return value;
} else if ( r == ESP_ERR_INVALID_STATE ) {
log_e("GPIO%u: %s: ADC2 not initialized yet.", pin, esp_err_to_name(r));
} else if ( r == ESP_ERR_TIMEOUT ) {
log_e("GPIO%u: %s: ADC2 is in use by Wi-Fi.", pin, esp_err_to_name(r));
} else {
log_e("GPIO%u: %s", pin, esp_err_to_name(r));
}
} else {
return adc1_get_raw(channel);
}
return value;
}
void __analogSetVRefPin(uint8_t pin){
if(pin <25 || pin > 27){
pin = 0;
}
__analogVRefPin = pin;
}
uint32_t __analogReadMilliVolts(uint8_t pin){
int8_t channel = digitalPinToAnalogChannel(pin);
if(channel < 0){
log_e("Pin %u is not ADC pin!", pin);
return 0;
}
if(!__analogVRef){
if (esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_TP) == ESP_OK) {
log_d("eFuse Two Point: Supported");
__analogVRef = DEFAULT_VREF;
}
if (esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_VREF) == ESP_OK) {
log_d("eFuse Vref: Supported");
__analogVRef = DEFAULT_VREF;
}
if(!__analogVRef){
__analogVRef = DEFAULT_VREF;
if(__analogVRefPin){
esp_adc_cal_characteristics_t chars;
if(adc2_vref_to_gpio(__analogVRefPin) == ESP_OK){
__analogVRef = __analogRead(__analogVRefPin);
esp_adc_cal_characterize(1, __analogAttenuation, __analogWidth, DEFAULT_VREF, &chars);
__analogVRef = esp_adc_cal_raw_to_voltage(__analogVRef, &chars);
log_d("Vref to GPIO%u: %u", __analogVRefPin, __analogVRef);
}
}
}
}
uint8_t unit = 1;
if(channel > 9){
unit = 2;
}
uint16_t adc_reading = __analogRead(pin);
if(__analogCharacteristics[unit - 1] == NULL){
__analogCharacteristics[unit - 1] = calloc(1, sizeof(esp_adc_cal_characteristics_t));
if(__analogCharacteristics[unit - 1] == NULL){
return 0;
}
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, __analogAttenuation, __analogWidth, __analogVRef, __analogCharacteristics[unit - 1]);
if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
log_i("ADC%u: Characterized using Two Point Value: %u\n", unit, __analogCharacteristics[unit - 1]->vref);
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
log_i("ADC%u: Characterized using eFuse Vref: %u\n", unit, __analogCharacteristics[unit - 1]->vref);
} else if(__analogVRef != DEFAULT_VREF){
log_i("ADC%u: Characterized using Vref to GPIO%u: %u\n", unit, __analogVRefPin, __analogCharacteristics[unit - 1]->vref);
} else {
log_i("ADC%u: Characterized using Default Vref: %u\n", unit, __analogCharacteristics[unit - 1]->vref);
}
}
return esp_adc_cal_raw_to_voltage(adc_reading, __analogCharacteristics[unit - 1]);
}
int __hallRead() //hall sensor without LNA
@ -260,14 +239,12 @@ int __hallRead() //hall sensor without LNA
extern uint16_t analogRead(uint8_t pin) __attribute__ ((weak, alias("__analogRead")));
extern void analogReadResolution(uint8_t bits) __attribute__ ((weak, alias("__analogReadResolution")));
extern void analogSetWidth(uint8_t bits) __attribute__ ((weak, alias("__analogSetWidth")));
extern void analogSetCycles(uint8_t cycles) __attribute__ ((weak, alias("__analogSetCycles")));
extern void analogSetSamples(uint8_t samples) __attribute__ ((weak, alias("__analogSetSamples")));
extern void analogSetClockDiv(uint8_t clockDiv) __attribute__ ((weak, alias("__analogSetClockDiv")));
extern void analogSetAttenuation(adc_attenuation_t attenuation) __attribute__ ((weak, alias("__analogSetAttenuation")));
extern void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation) __attribute__ ((weak, alias("__analogSetPinAttenuation")));
extern int hallRead() __attribute__ ((weak, alias("__hallRead")));
extern bool adcAttachPin(uint8_t pin) __attribute__ ((weak, alias("__adcAttachPin")));
extern bool adcStart(uint8_t pin) __attribute__ ((weak, alias("__adcStart")));
extern bool adcBusy(uint8_t pin) __attribute__ ((weak, alias("__adcBusy")));
extern uint16_t adcEnd(uint8_t pin) __attribute__ ((weak, alias("__adcEnd")));
extern void analogSetVRefPin(uint8_t pin) __attribute__ ((weak, alias("__analogSetVRefPin")));
extern uint32_t analogReadMilliVolts(uint8_t pin) __attribute__ ((weak, alias("__analogReadMilliVolts")));

View File

@ -54,24 +54,6 @@ void analogReadResolution(uint8_t bits);
* */
void analogSetWidth(uint8_t bits);
/*
* Set number of cycles per sample
* Default is 8 and seems to do well
* Range is 1 - 255
* */
void analogSetCycles(uint8_t cycles);
/*
* Set number of samples in the range.
* Default is 1
* Range is 1 - 255
* This setting splits the range into
* "samples" pieces, which could look
* like the sensitivity has been multiplied
* that many times
* */
void analogSetSamples(uint8_t samples);
/*
* Set the divider for the ADC clock.
* Default is 1
@ -97,34 +79,20 @@ void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation);
* */
int hallRead();
/*
* Non-Blocking API (almost)
*
* Note: ADC conversion can run only for single pin at a time.
* That means that if you want to run ADC on two pins on the same bus,
* you need to run them one after another. Probably the best use would be
* to start conversion on both buses in parallel.
* */
/*
* Attach pin to ADC (will also clear any other analog mode that could be on)
* */
bool adcAttachPin(uint8_t pin);
/*
* Start ADC conversion on attached pin's bus
* Set pin to use for ADC calibration if the esp is not already calibrated (25, 26 or 27)
* */
bool adcStart(uint8_t pin);
void analogSetVRefPin(uint8_t pin);
/*
* Check if conversion on the pin's ADC bus is currently running
* Get MilliVolts value for pin
* */
bool adcBusy(uint8_t pin);
/*
* Get the result of the conversion (will wait if it have not finished)
* */
uint16_t adcEnd(uint8_t pin);
uint32_t analogReadMilliVolts(uint8_t pin);
#ifdef __cplusplus
}

View File

@ -65,6 +65,14 @@ bool btStop(){
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED);
}
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED){
if (esp_bt_controller_deinit()) {
log_e("BT deint failed");
return false;
}
vTaskDelay(1);
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_IDLE) {
return false;
}
return true;
}
log_e("BT Stop failed");

View File

@ -21,13 +21,24 @@
#include "esp_log.h"
#include "soc/rtc.h"
#include "soc/rtc_cntl_reg.h"
#include "rom/rtc.h"
#include "soc/apb_ctrl_reg.h"
#include "soc/efuse_reg.h"
#include "esp32-hal.h"
#include "esp32-hal-cpu.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/rtc.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/rtc.h"
#endif
typedef struct apb_change_cb_s {
struct apb_change_cb_s * prev;
struct apb_change_cb_s * next;
void * arg;
apb_change_cb_t cb;
@ -53,9 +64,19 @@ static void triggerApbChangeCallback(apb_change_ev_t ev_type, uint32_t old_apb,
initApbChangeCallback();
xSemaphoreTake(apb_change_lock, portMAX_DELAY);
apb_change_t * r = apb_change_callbacks;
while(r != NULL){
r->cb(r->arg, ev_type, old_apb, new_apb);
r=r->next;
if( r != NULL ){
if(ev_type == APB_BEFORE_CHANGE )
while(r != NULL){
r->cb(r->arg, ev_type, old_apb, new_apb);
r=r->next;
}
else { // run backwards through chain
while(r->next != NULL) r = r->next; // find first added
while( r != NULL){
r->cb(r->arg, ev_type, old_apb, new_apb);
r=r->prev;
}
}
}
xSemaphoreGive(apb_change_lock);
}
@ -68,6 +89,7 @@ bool addApbChangeCallback(void * arg, apb_change_cb_t cb){
return false;
}
c->next = NULL;
c->prev = NULL;
c->arg = arg;
c->cb = cb;
xSemaphoreTake(apb_change_lock, portMAX_DELAY);
@ -75,18 +97,20 @@ bool addApbChangeCallback(void * arg, apb_change_cb_t cb){
apb_change_callbacks = c;
} else {
apb_change_t * r = apb_change_callbacks;
if(r->cb != cb || r->arg != arg){
while(r->next){
r = r->next;
if(r->cb == cb && r->arg == arg){
free(c);
goto unlock_and_exit;
}
}
r->next = c;
// look for duplicate callbacks
while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next;
if (r) {
log_e("duplicate func=%08X arg=%08X",c->cb,c->arg);
free(c);
xSemaphoreGive(apb_change_lock);
return false;
}
else {
c->next = apb_change_callbacks;
apb_change_callbacks-> prev = c;
apb_change_callbacks = c;
}
}
unlock_and_exit:
xSemaphoreGive(apb_change_lock);
return true;
}
@ -95,24 +119,21 @@ bool removeApbChangeCallback(void * arg, apb_change_cb_t cb){
initApbChangeCallback();
xSemaphoreTake(apb_change_lock, portMAX_DELAY);
apb_change_t * r = apb_change_callbacks;
if(r == NULL){
// look for matching callback
while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next;
if ( r == NULL ) {
log_e("not found func=%08X arg=%08X",cb,arg);
xSemaphoreGive(apb_change_lock);
return false;
}
if(r->cb == cb && r->arg == arg){
apb_change_callbacks = r->next;
}
else {
// patch links
if(r->prev) r->prev->next = r->next;
else { // this is first link
apb_change_callbacks = r->next;
}
if(r->next) r->next->prev = r->prev;
free(r);
} else {
while(r->next && (r->next->cb != cb || r->next->arg != arg)){
r = r->next;
}
if(r->next == NULL || r->next->cb != cb || r->next->arg != arg){
xSemaphoreGive(apb_change_lock);
return false;
}
apb_change_t * c = r->next;
r->next = c->next;
free(c);
}
xSemaphoreGive(apb_change_lock);
return true;
@ -186,7 +207,7 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz){
//Update REF_TICK (uncomment if REF_TICK is different than 1MHz)
//if(conf.freq_mhz < 80){
// ESP_REG(APB_CTRL_XTAL_TICK_CONF_REG) = conf.freq_mhz / (REF_CLK_FREQ / MHZ) - 1;
//}
// }
//Update APB Freq REG
rtc_clk_apb_freq_update(apb);
//Update esp_timer divisor

View File

@ -15,13 +15,24 @@
#include "esp32-hal-dac.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "rom/ets_sys.h"
#include "esp_attr.h"
#include "esp_intr.h"
#include "soc/rtc_io_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/sens_reg.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#include "esp_intr_alloc.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#include "esp_intr.h"
#endif
void IRAM_ATTR __dacWrite(uint8_t pin, uint8_t value)
{
if(pin < 25 || pin > 26){

View File

@ -15,15 +15,27 @@
#include "esp32-hal-gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "rom/ets_sys.h"
#include "esp_attr.h"
#include "esp_intr.h"
#include "rom/gpio.h"
#include "soc/gpio_reg.h"
#include "soc/io_mux_reg.h"
#include "soc/gpio_struct.h"
#include "soc/rtc_io_reg.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#include "esp32/rom/gpio.h"
#include "esp_intr_alloc.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#include "rom/gpio.h"
#include "esp_intr.h"
#endif
const int8_t esp32_adc2gpio[20] = {36, 37, 38, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26};
const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={
@ -59,8 +71,8 @@ const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={
{0, -1, -1, -1},
{0, -1, -1, -1},
{0, -1, -1, -1},
{0x1c, 9, 4, 9},
{0x20, 8, 5, 8},
{0x1c, 9, 4, 8},
{0x20, 8, 5, 9},
{0x14, 4, 6, -1},
{0x18, 5, 7, -1},
{0x04, 0, 0, -1},

View File

@ -18,13 +18,25 @@
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"
#include "rom/ets_sys.h"
#include "driver/periph_ctrl.h"
#include "soc/i2c_reg.h"
#include "soc/i2c_struct.h"
#include "soc/dport_reg.h"
#include "esp_attr.h"
#include "esp32-hal-cpu.h" // cpu clock change support 31DEC2018
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#endif
//#define I2C_DEV(i) (volatile i2c_dev_t *)((i)?DR_REG_I2C1_EXT_BASE:DR_REG_I2C_EXT_BASE)
//#define I2C_DEV(i) ((i2c_dev_t *)(REG_I2C_BASE(i)))
#define I2C_SCL_IDX(p) ((p==0)?I2CEXT0_SCL_OUT_IDX:((p==1)?I2CEXT1_SCL_OUT_IDX:0))

View File

@ -16,19 +16,29 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "rom/ets_sys.h"
#include "esp32-hal-matrix.h"
#include "soc/dport_reg.h"
#include "soc/ledc_reg.h"
#include "soc/ledc_struct.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#endif
#if CONFIG_DISABLE_HAL_LOCKS
#define LEDC_MUTEX_LOCK()
#define LEDC_MUTEX_UNLOCK()
#else
#define LEDC_MUTEX_LOCK() do {} while (xSemaphoreTake(_ledc_sys_lock, portMAX_DELAY) != pdPASS)
#define LEDC_MUTEX_UNLOCK() xSemaphoreGive(_ledc_sys_lock)
xSemaphoreHandle _ledc_sys_lock;
xSemaphoreHandle _ledc_sys_lock = NULL;
#endif
/*
@ -55,27 +65,35 @@ xSemaphoreHandle _ledc_sys_lock;
static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb){
if(ev_type == APB_AFTER_CHANGE && old_apb != new_apb){
uint32_t iarg = (uint32_t)arg;
uint8_t chan = iarg;
uint8_t group=(chan/8), timer=((chan/2)%4);
uint16_t iarg = *(uint16_t*)arg;
uint8_t chan = 0;
old_apb /= 1000000;
new_apb /= 1000000;
if(LEDC_TIMER(group, timer).conf.tick_sel){
LEDC_MUTEX_LOCK();
uint32_t old_div = LEDC_TIMER(group, timer).conf.clock_divider;
uint32_t div_num = (new_apb * old_div) / old_apb;
if(div_num > LEDC_DIV_NUM_HSTIMER0_V){
new_apb = REF_CLK_FREQ / 1000000;
div_num = (new_apb * old_div) / old_apb;
if(div_num > LEDC_DIV_NUM_HSTIMER0_V) {
div_num = LEDC_DIV_NUM_HSTIMER0_V;//lowest clock possible
while(iarg){ // run though all active channels, adjusting timing configurations
if(iarg & 1) {// this channel is active
uint8_t group=(chan/8), timer=((chan/2)%4);
if(LEDC_TIMER(group, timer).conf.tick_sel){
LEDC_MUTEX_LOCK();
uint32_t old_div = LEDC_TIMER(group, timer).conf.clock_divider;
uint32_t div_num = (new_apb * old_div) / old_apb;
if(div_num > LEDC_DIV_NUM_HSTIMER0_V){
div_num = ((REF_CLK_FREQ /1000000) * old_div) / old_apb;
if(div_num > LEDC_DIV_NUM_HSTIMER0_V) {
div_num = LEDC_DIV_NUM_HSTIMER0_V;//lowest clock possible
}
LEDC_TIMER(group, timer).conf.tick_sel = 0;
} else if(div_num < 256) {
div_num = 256;//highest clock possible
}
LEDC_TIMER(group, timer).conf.clock_divider = div_num;
LEDC_MUTEX_UNLOCK();
}
else {
log_d("using REF_CLK chan=%d",chan);
}
LEDC_TIMER(group, timer).conf.tick_sel = 0;
} else if(div_num < 256) {
div_num = 256;//highest clock possible
}
LEDC_TIMER(group, timer).conf.clock_divider = div_num;
LEDC_MUTEX_UNLOCK();
iarg = iarg >> 1;
chan++;
}
}
}
@ -85,11 +103,14 @@ static void _ledcSetupTimer(uint8_t chan, uint32_t div_num, uint8_t bit_num, boo
{
uint8_t group=(chan/8), timer=((chan/2)%4);
static bool tHasStarted = false;
static uint16_t _activeChannels = 0;
if(!tHasStarted) {
tHasStarted = true;
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_LEDC_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_LEDC_RST);
LEDC.conf.apb_clk_sel = 1;//LS use apb clock
addApbChangeCallback((void*)&_activeChannels, _on_apb_change);
#if !CONFIG_DISABLE_HAL_LOCKS
_ledc_sys_lock = xSemaphoreCreateMutex();
#endif
@ -105,8 +126,7 @@ static void _ledcSetupTimer(uint8_t chan, uint32_t div_num, uint8_t bit_num, boo
LEDC_TIMER(group, timer).conf.rst = 1;//This bit is used to reset timer the counter will be 0 after reset.
LEDC_TIMER(group, timer).conf.rst = 0;
LEDC_MUTEX_UNLOCK();
uint32_t iarg = chan;
addApbChangeCallback((void*)iarg, _on_apb_change);
_activeChannels |= (1 << chan); // mark as active for APB callback
}
//max div_num 0x3FFFF (262143)

View File

@ -14,7 +14,17 @@
#include "esp32-hal-matrix.h"
#include "esp_attr.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/gpio.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/gpio.h"
#endif
#define MATRIX_DETACH_OUT_SIG 0x100
#define MATRIX_DETACH_IN_LOW_PIN 0x30

View File

@ -31,10 +31,20 @@
#include "soc/rtc.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/apb_ctrl_reg.h"
#include "rom/rtc.h"
#include "esp_task_wdt.h"
#include "esp32-hal.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/rtc.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/rtc.h"
#endif
//Undocumented!!! Get chip temperature in Farenheit
//Source: https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_int_temp_sensor/ESP32_int_temp_sensor.ino
uint8_t temprature_sens_read();
@ -44,11 +54,13 @@ float temperatureRead()
return (temprature_sens_read() - 32) / 1.8;
}
void yield()
void __yield()
{
vPortYield();
}
void yield() __attribute__ ((weak, alias("__yield")));
#if CONFIG_AUTOSTART_ARDUINO
extern TaskHandle_t loopTaskHandle;

View File

@ -1,11 +1,34 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "esp32-hal.h"
#if CONFIG_SPIRAM_SUPPORT
#include "esp_spiram.h"
#include "soc/efuse_reg.h"
#include "esp_heap_caps.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/spiram.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "esp_spiram.h"
#endif
static volatile bool spiramDetected = false;
static volatile bool spiramFailed = false;

View File

@ -128,7 +128,7 @@ static xSemaphoreHandle g_rmt_block_lock = NULL;
*/
static void _initPin(int pin, int channel, bool tx_not_rx);
static bool _rmtSendOnce(rmt_obj_t* rmt, rmt_data_t* data, size_t size);
static bool _rmtSendOnce(rmt_obj_t* rmt, rmt_data_t* data, size_t size, bool continuous);
static void IRAM_ATTR _rmt_isr(void* arg);
@ -234,6 +234,20 @@ bool rmtDeinit(rmt_obj_t *rmt)
return true;
}
bool rmtLoop(rmt_obj_t* rmt, rmt_data_t* data, size_t size)
{
if (!rmt) {
return false;
}
int allocated_size = MAX_DATA_PER_CHANNEL * rmt->buffers;
if (size > allocated_size) {
return false;
}
return _rmtSendOnce(rmt, data, size, true);
}
bool rmtWrite(rmt_obj_t* rmt, rmt_data_t* data, size_t size)
{
if (!rmt) {
@ -282,10 +296,10 @@ bool rmtWrite(rmt_obj_t* rmt, rmt_data_t* data, size_t size)
RMT_MUTEX_UNLOCK(channel);
// start the transation
return _rmtSendOnce(rmt, data, MAX_DATA_PER_ITTERATION);
return _rmtSendOnce(rmt, data, MAX_DATA_PER_ITTERATION, false);
} else {
// use one-go mode if data fits one buffer
return _rmtSendOnce(rmt, data, size);
return _rmtSendOnce(rmt, data, size, false);
}
}
@ -483,7 +497,7 @@ rmt_obj_t* rmtInit(int pin, bool tx_not_rx, rmt_reserve_memsize_t memsize)
break;
}
}
if (i == MAX_CHANNELS || i+j >= MAX_CHANNELS || j != buffers) {
if (i == MAX_CHANNELS || i+j > MAX_CHANNELS || j != buffers) {
xSemaphoreGive(g_rmt_block_lock);
return NULL;
}
@ -553,7 +567,7 @@ rmt_obj_t* rmtInit(int pin, bool tx_not_rx, rmt_reserve_memsize_t memsize)
/**
* Private methods definitions
*/
bool _rmtSendOnce(rmt_obj_t* rmt, rmt_data_t* data, size_t size)
bool _rmtSendOnce(rmt_obj_t* rmt, rmt_data_t* data, size_t size, bool continuous)
{
if (!rmt) {
return false;
@ -571,6 +585,7 @@ bool _rmtSendOnce(rmt_obj_t* rmt, rmt_data_t* data, size_t size)
}
RMT_MUTEX_LOCK(channel);
RMT.conf_ch[channel].conf1.tx_conti_mode = continuous;
RMT.conf_ch[channel].conf1.mem_rd_rst = 1;
RMT.conf_ch[channel].conf1.tx_start = 1;
RMT_MUTEX_UNLOCK(channel);

View File

@ -73,6 +73,12 @@ float rmtSetTick(rmt_obj_t* rmt, float tick);
*/
bool rmtWrite(rmt_obj_t* rmt, rmt_data_t* data, size_t size);
/**
* Loop data up to the reserved memsize continuously
*
*/
bool rmtLoop(rmt_obj_t* rmt, rmt_data_t* data, size_t size);
/**
* Initiates async receive, event flag indicates data received
*

View File

@ -16,11 +16,21 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "rom/ets_sys.h"
#include "esp32-hal-matrix.h"
#include "soc/gpio_sd_reg.h"
#include "soc/gpio_sd_struct.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#endif
#if CONFIG_DISABLE_HAL_LOCKS
#define SD_MUTEX_LOCK()

View File

@ -17,10 +17,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "rom/ets_sys.h"
#include "esp_attr.h"
#include "esp_intr.h"
#include "rom/gpio.h"
#include "soc/spi_reg.h"
#include "soc/spi_struct.h"
#include "soc/io_mux_reg.h"
@ -28,6 +25,21 @@
#include "soc/dport_reg.h"
#include "soc/rtc.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#include "esp32/rom/gpio.h"
#include "esp_intr_alloc.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#include "rom/gpio.h"
#include "esp_intr.h"
#endif
#define SPI_CLK_IDX(p) ((p==0)?SPICLK_OUT_IDX:((p==1)?SPICLK_OUT_IDX:((p==2)?HSPICLK_OUT_IDX:((p==3)?VSPICLK_OUT_IDX:0))))
#define SPI_MISO_IDX(p) ((p==0)?SPIQ_OUT_IDX:((p==1)?SPIQ_OUT_IDX:((p==2)?HSPIQ_OUT_IDX:((p==3)?VSPIQ_OUT_IDX:0))))
#define SPI_MOSI_IDX(p) ((p==0)?SPID_IN_IDX:((p==1)?SPID_IN_IDX:((p==2)?HSPID_IN_IDX:((p==3)?VSPID_IN_IDX:0))))
@ -421,14 +433,14 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_
#endif
if(spi_num == HSPI) {
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST);
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI2_RST);
} else if(spi_num == VSPI) {
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN_2);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST_2);
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI3_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI3_RST);
} else {
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN_1);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST_1);
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST);
}
spiStopBus(spi);
@ -459,7 +471,7 @@ void spiWaitReady(spi_t * spi)
while(spi->dev->cmd.usr);
}
void spiWrite(spi_t * spi, uint32_t *data, uint8_t len)
void spiWrite(spi_t * spi, const uint32_t *data, uint8_t len)
{
if(!spi) {
return;
@ -532,17 +544,7 @@ uint8_t spiTransferByte(spi_t * spi, uint8_t data)
return data;
}
uint32_t __spiTranslate24(uint32_t data)
{
union {
uint32_t l;
uint8_t b[4];
} out;
out.l = data;
return out.b[2] | (out.b[1] << 8) | (out.b[0] << 16);
}
uint32_t __spiTranslate32(uint32_t data)
static uint32_t __spiTranslate32(uint32_t data)
{
union {
uint32_t l;
@ -630,7 +632,7 @@ uint32_t spiTransferLong(spi_t * spi, uint32_t data)
return data;
}
void __spiTransferBytes(spi_t * spi, uint8_t * data, uint8_t * out, uint32_t bytes)
static void __spiTransferBytes(spi_t * spi, const uint8_t * data, uint8_t * out, uint32_t bytes)
{
if(!spi) {
return;
@ -671,7 +673,7 @@ void __spiTransferBytes(spi_t * spi, uint8_t * data, uint8_t * out, uint32_t byt
}
}
void spiTransferBytes(spi_t * spi, uint8_t * data, uint8_t * out, uint32_t size)
void spiTransferBytes(spi_t * spi, const uint8_t * data, uint8_t * out, uint32_t size)
{
if(!spi) {
return;
@ -861,7 +863,7 @@ uint32_t spiTransferLongNL(spi_t * spi, uint32_t data)
return data;
}
void spiWriteNL(spi_t * spi, const void * data_in, size_t len){
void spiWriteNL(spi_t * spi, const void * data_in, uint32_t len){
size_t longs = len >> 2;
if(len & 3){
longs++;
@ -887,7 +889,7 @@ void spiWriteNL(spi_t * spi, const void * data_in, size_t len){
}
}
void spiTransferBytesNL(spi_t * spi, const void * data_in, uint8_t * data_out, size_t len){
void spiTransferBytesNL(spi_t * spi, const void * data_in, uint8_t * data_out, uint32_t len){
if(!spi) {
return;
}
@ -974,7 +976,7 @@ void spiTransferBitsNL(spi_t * spi, uint32_t data, uint32_t * out, uint8_t bits)
}
}
void IRAM_ATTR spiWritePixelsNL(spi_t * spi, const void * data_in, size_t len){
void IRAM_ATTR spiWritePixelsNL(spi_t * spi, const void * data_in, uint32_t len){
size_t longs = len >> 2;
if(len & 3){
longs++;

View File

@ -96,7 +96,7 @@ void spiSetClockDiv(spi_t * spi, uint32_t clockDiv);
void spiSetDataMode(spi_t * spi, uint8_t dataMode);
void spiSetBitOrder(spi_t * spi, uint8_t bitOrder);
void spiWrite(spi_t * spi, uint32_t *data, uint8_t len);
void spiWrite(spi_t * spi, const uint32_t *data, uint8_t len);
void spiWriteByte(spi_t * spi, uint8_t data);
void spiWriteWord(spi_t * spi, uint16_t data);
void spiWriteLong(spi_t * spi, uint32_t data);
@ -105,7 +105,7 @@ void spiTransfer(spi_t * spi, uint32_t *out, uint8_t len);
uint8_t spiTransferByte(spi_t * spi, uint8_t data);
uint16_t spiTransferWord(spi_t * spi, uint16_t data);
uint32_t spiTransferLong(spi_t * spi, uint32_t data);
void spiTransferBytes(spi_t * spi, uint8_t * data, uint8_t * out, uint32_t size);
void spiTransferBytes(spi_t * spi, const uint8_t * data, uint8_t * out, uint32_t size);
void spiTransferBits(spi_t * spi, uint32_t data, uint32_t * out, uint8_t bits);
/*
@ -115,11 +115,11 @@ void spiTransaction(spi_t * spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bi
void spiSimpleTransaction(spi_t * spi);
void spiEndTransaction(spi_t * spi);
void spiWriteNL(spi_t * spi, const void * data, uint32_t len);
void spiWriteNL(spi_t * spi, const void * data_in, uint32_t len);
void spiWriteByteNL(spi_t * spi, uint8_t data);
void spiWriteShortNL(spi_t * spi, uint16_t data);
void spiWriteLongNL(spi_t * spi, uint32_t data);
void spiWritePixelsNL(spi_t * spi, const void * data, uint32_t len);
void spiWritePixelsNL(spi_t * spi, const void * data_in, uint32_t len);
#define spiTransferNL(spi, data, len) spiTransferBytesNL(spi, data, data, len)
uint8_t spiTransferByteNL(spi_t * spi, uint8_t data);

View File

@ -14,6 +14,7 @@
#include "esp32-hal.h"
#include "lwip/apps/sntp.h"
#include "tcpip_adapter.h"
static void setTimeZone(long offset, int daylight)
{
@ -45,6 +46,7 @@ static void setTimeZone(long offset, int daylight)
* */
void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
{
tcpip_adapter_init(); // Should not hurt anything if already inited
if(sntp_enabled()){
sntp_stop();
}
@ -62,6 +64,7 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1,
* */
void configTzTime(const char* tz, const char* server1, const char* server2, const char* server3)
{
tcpip_adapter_init(); // Should not hurt anything if already inited
if(sntp_enabled()){
sntp_stop();
}

View File

@ -16,11 +16,22 @@
#include "freertos/FreeRTOS.h"
#include "freertos/xtensa_api.h"
#include "freertos/task.h"
#include "rom/ets_sys.h"
#include "soc/timer_group_struct.h"
#include "soc/dport_reg.h"
#include "esp_attr.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#include "esp_intr_alloc.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#include "esp_intr.h"
#endif
#define HWTIMER_LOCK() portENTER_CRITICAL(timer->lock)
#define HWTIMER_UNLOCK() portEXIT_CRITICAL(timer->lock)

View File

@ -15,13 +15,24 @@
#include "esp32-hal-touch.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "rom/ets_sys.h"
#include "esp_attr.h"
#include "esp_intr.h"
#include "soc/rtc_io_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/sens_reg.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#include "esp_intr_alloc.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#include "esp_intr.h"
#endif
static uint16_t __touchSleepCycles = 0x1000;
static uint16_t __touchMeasureCycles = 0x1000;

View File

@ -18,10 +18,7 @@
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "rom/ets_sys.h"
#include "esp_attr.h"
#include "esp_intr.h"
#include "rom/uart.h"
#include "soc/uart_reg.h"
#include "soc/uart_struct.h"
#include "soc/io_mux_reg.h"
@ -30,6 +27,20 @@
#include "soc/rtc.h"
#include "esp_intr_alloc.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/ets_sys.h"
#include "esp32/rom/uart.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/ets_sys.h"
#include "rom/uart.h"
#include "esp_intr.h"
#endif
#define UART_REG_BASE(u) ((u==0)?DR_REG_UART_BASE:( (u==1)?DR_REG_UART1_BASE:( (u==2)?DR_REG_UART2_BASE:0)))
#define UART_RXD_IDX(u) ((u==0)?U0RXD_IN_IDX:( (u==1)?U1RXD_IN_IDX:( (u==2)?U2RXD_IN_IDX:0)))
#define UART_TXD_IDX(u) ((u==0)?U0TXD_OUT_IDX:( (u==1)?U1TXD_OUT_IDX:( (u==2)?U2TXD_OUT_IDX:0)))
@ -217,7 +228,6 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
if(txPin != -1) {
uartAttachTx(uart, txPin, inverted);
}
addApbChangeCallback(uart, uart_on_apb_change);
return uart;
}
@ -253,7 +263,7 @@ size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
vQueueDelete(uart->queue);
uart->queue = xQueueCreate(new_size, sizeof(uint8_t));
if(uart->queue == NULL) {
return NULL;
return 0;
}
}
UART_MUTEX_UNLOCK();
@ -327,6 +337,11 @@ void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len)
}
void uartFlush(uart_t* uart)
{
uartFlushTxOnly(uart,false);
}
void uartFlushTxOnly(uart_t* uart, bool txOnly)
{
if(uart == NULL) {
return;
@ -334,17 +349,19 @@ void uartFlush(uart_t* uart)
UART_MUTEX_LOCK();
while(uart->dev->status.txfifo_cnt || uart->dev->status.st_utx_out);
if( !txOnly ){
//Due to hardware issue, we can not use fifo_rst to reset uart fifo.
//See description about UART_TXFIFO_RST and UART_RXFIFO_RST in <<esp32_technical_reference_manual>> v2.6 or later.
//Due to hardware issue, we can not use fifo_rst to reset uart fifo.
//See description about UART_TXFIFO_RST and UART_RXFIFO_RST in <<esp32_technical_reference_manual>> v2.6 or later.
// we read the data out and make `fifo_len == 0 && rd_addr == wr_addr`.
while(uart->dev->status.rxfifo_cnt != 0 || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) {
READ_PERI_REG(UART_FIFO_REG(uart->num));
}
// we read the data out and make `fifo_len == 0 && rd_addr == wr_addr`.
while(uart->dev->status.rxfifo_cnt != 0 || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) {
READ_PERI_REG(UART_FIFO_REG(uart->num));
xQueueReset(uart->queue);
}
xQueueReset(uart->queue);
UART_MUTEX_UNLOCK();
}
@ -370,18 +387,21 @@ static void uart_on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old
uart->dev->int_clr.val = 0xffffffff;
// read RX fifo
uint8_t c;
BaseType_t xHigherPriorityTaskWoken;
// BaseType_t xHigherPriorityTaskWoken;
while(uart->dev->status.rxfifo_cnt != 0 || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) {
c = uart->dev->fifo.rw_byte;
if(uart->queue != NULL && !xQueueIsQueueFullFromISR(uart->queue)) {
xQueueSendFromISR(uart->queue, &c, &xHigherPriorityTaskWoken);
if(uart->queue != NULL ) {
xQueueSend(uart->queue, &c, 1); //&xHigherPriorityTaskWoken);
}
}
UART_MUTEX_UNLOCK();
// wait TX empty
while(uart->dev->status.txfifo_cnt || uart->dev->status.st_utx_out);
} else {
//todo:
// set baudrate
UART_MUTEX_LOCK();
uint32_t clk_div = (uart->dev->clk_div.div_int << 4) | (uart->dev->clk_div.div_frag & 0x0F);
uint32_t baud_rate = ((old_apb<<4)/clk_div);
clk_div = ((new_apb<<4)/baud_rate);

View File

@ -63,6 +63,7 @@ void uartWrite(uart_t* uart, uint8_t c);
void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len);
void uartFlush(uart_t* uart);
void uartFlushTxOnly(uart_t* uart, bool txOnly );
void uartSetBaudRate(uart_t* uart, uint32_t baud_rate);
uint32_t uartGetBaudRate(uart_t* uart);

View File

@ -34,6 +34,7 @@ extern "C" {
#include <math.h>
#include "sdkconfig.h"
#include "esp_system.h"
#include "esp_sleep.h"
#ifndef F_CPU
#define F_CPU (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000U)

View File

@ -17,6 +17,7 @@ void loopTask(void *pvParameters)
esp_task_wdt_reset();
}
loop();
if (serialEventRun) serialEventRun();
}
}

View File

@ -1,13 +1,12 @@
Installation instructions using Arduino IDE Boards Manager
==========================================================
## Installation instructions using Arduino IDE Boards Manager
### ==========================================================
Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (32 and 64 bit).
- Stable release link: `https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json`
- Development release link: `https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json`
Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (32, 64 bit and ARM).
- Install the current upstream Arduino IDE at the 1.8 level or later. The current version is at the [Arduino website](http://www.arduino.cc/en/main/software).
- Start Arduino and open Preferences window.
- Enter ```https://dl.espressif.com/dl/package_esp32_index.json``` into *Additional Board Manager URLs* field. You can add multiple URLs, separating them with commas.
- Enter one of the release links above into *Additional Board Manager URLs* field. You can add multiple URLs, separating them with commas.
- Open Boards Manager from Tools > Board menu and install *esp32* platform (and don't forget to select your ESP32 board from Tools > Board menu after installation).
Stable release link: `https://dl.espressif.com/dl/package_esp32_index.json`
Development release link: `https://dl.espressif.com/dl/package_esp32_dev_index.json`

View File

@ -1,6 +1,10 @@
To use as a component of ESP-IDF
=================================================
## esp32-arduino-lib-builder
For a simplified method, see [lib-builder](lib_builder.md)
## Installation
- Download and install [esp-idf](https://github.com/espressif/esp-idf)

14
docs/lib_builder.md Normal file
View File

@ -0,0 +1,14 @@
## Using esp32-arduino-lib-builder to compile custom libraries
Espressif has provided a [tool](https://github.com/espressif/esp32-arduino-lib-builder) to simplify building your own compiled libraries for use in Arduino IDE (or your favorite IDE).
To use it to generate custom libraries, follow these steps:
1. `git clone https://github.com/espressif/esp32-arduino-lib-builder`
2. `cd esp32-arduino-lib-builder`
3. `./tools/update-components.sh`
4. `./tools/install-esp-idf.sh` (if you already have an $IDF_PATH defined, it will use your local copy of the repository)
5. `make menuconfig` or directly edit sdkconfig.
6. `./build.sh`
The script automates the process of building [arduino as an ESP-IDF component](https://github.com/espressif/arduino-esp32/blob/master/docs/esp-idf_component.md).
Once it is complete, you can cherry pick the needed libraries from `out/tools/sdk/lib`, or run `tools/copy-to-arduino.sh` to copy the entire built system.
`tools/config.sh` contains a number of variables that control the process, particularly the $IDF_BRANCH variable. You can adjust this to try building against newer versions, but there are absolutely no guarantees that any components will work or even successfully compile against a newer IDF.

View File

@ -154,7 +154,7 @@ void loop() {
// Set the characteristic's value to be the array of bytes that is actually a string.
pRemoteCharacteristic->writeValue(newValue.c_str(), newValue.length());
}else if(doScan){
BLEDevice::getScan()->start(0); // this is just eample to start scan after disconnect, most likely there is better way to do it in arduino
BLEDevice::getScan()->start(0); // this is just example to start scan after disconnect, most likely there is better way to do it in arduino
}
delay(1000); // Delay a second between loops.

View File

@ -65,6 +65,7 @@ void setBeacon() {
pAdvertising->setAdvertisementData(oAdvertisementData);
pAdvertising->setScanResponseData(oScanResponseData);
pAdvertising->setAdvertisementType(ADV_TYPE_NONCONN_IND);
}

View File

@ -25,7 +25,8 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
m_manufacturerData = "";
m_name = "";
m_rssi = -9999;
m_serviceData = "";
m_serviceData = {};
m_serviceDataUUIDs = {};
m_txPower = 0;
m_pScan = nullptr;
@ -101,33 +102,66 @@ BLEScan* BLEAdvertisedDevice::getScan() {
return m_pScan;
} // getScan
/**
* @brief Get the number of service data.
* @return Number of service data discovered.
*/
int BLEAdvertisedDevice::getServiceDataCount() {
if (m_haveServiceData)
return m_serviceData.size();
else
return 0;
} //getServiceDataCount
/**
* @brief Get the service data.
* @return The ServiceData of the advertised device.
*/
std::string BLEAdvertisedDevice::getServiceData() {
return m_serviceData;
return m_serviceData[0];
} //getServiceData
/**
* @brief Get the service data.
* @return The ServiceData of the advertised device.
*/
std::string BLEAdvertisedDevice::getServiceData(int i) {
return m_serviceData[i];
} //getServiceData
/**
* @brief Get the service data UUID.
* @return The service data UUID.
*/
BLEUUID BLEAdvertisedDevice::getServiceDataUUID() {
return m_serviceDataUUID;
return m_serviceDataUUIDs[0];
} // getServiceDataUUID
/**
* @brief Get the service data UUID.
* @return The service data UUID.
*/
BLEUUID BLEAdvertisedDevice::getServiceDataUUID(int i) {
return m_serviceDataUUIDs[i];
} // getServiceDataUUID
/**
* @brief Get the Service UUID.
* @return The Service UUID of the advertised device.
*/
BLEUUID BLEAdvertisedDevice::getServiceUUID() { //TODO Remove it eventually, is no longer useful
BLEUUID BLEAdvertisedDevice::getServiceUUID() {
return m_serviceUUIDs[0];
} // getServiceUUID
/**
* @brief Get the Service UUID.
* @return The Service UUID of the advertised device.
*/
BLEUUID BLEAdvertisedDevice::getServiceUUID(int i) {
return m_serviceUUIDs[i];
} // getServiceUUID
/**
* @brief Check advertised serviced for existence required UUID
* @return Return true if service is advertised
@ -454,7 +488,7 @@ void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
*/
void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
m_haveServiceData = true; // Set the flag that indicates we have service data.
m_serviceData = serviceData; // Save the service data that we received.
m_serviceData.push_back(serviceData); // Save the service data that we received.
} //setServiceData
@ -464,7 +498,8 @@ void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
*/
void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
m_haveServiceData = true; // Set the flag that indicates we have service data.
m_serviceDataUUID = uuid;
m_serviceDataUUIDs.push_back(uuid);
log_d("- addServiceDataUUID(): serviceDataUUID: %s", uuid.toString().c_str());
} // setServiceDataUUID
@ -498,10 +533,12 @@ std::string BLEAdvertisedDevice::toString() {
free(pHex);
}
if (haveServiceUUID()) {
res += ", serviceUUID: " + getServiceUUID().toString();
for (int i=0; i < m_serviceUUIDs.size(); i++) {
res += ", serviceUUID: " + getServiceUUID(i).toString();
}
}
if (haveTXPower()) {
char val[4];
char val[6];
snprintf(val, sizeof(val), "%d", getTXPower());
res += ", txPower: ";
res += val;

View File

@ -12,6 +12,7 @@
#include <esp_gattc_api.h>
#include <map>
#include <vector>
#include "BLEAddress.h"
#include "BLEScan.h"
@ -36,8 +37,12 @@ public:
int getRSSI();
BLEScan* getScan();
std::string getServiceData();
std::string getServiceData(int i);
BLEUUID getServiceDataUUID();
BLEUUID getServiceDataUUID(int i);
BLEUUID getServiceUUID();
BLEUUID getServiceUUID(int i);
int getServiceDataCount();
int8_t getTXPower();
uint8_t* getPayload();
size_t getPayloadLength();
@ -93,8 +98,8 @@ private:
int m_rssi;
std::vector<BLEUUID> m_serviceUUIDs;
int8_t m_txPower;
std::string m_serviceData;
BLEUUID m_serviceDataUUID;
std::vector<std::string> m_serviceData;
std::vector<BLEUUID> m_serviceDataUUIDs;
uint8_t* m_payload;
size_t m_payloadLength = 0;
esp_ble_addr_type_t m_addressType;

View File

@ -85,6 +85,10 @@ void BLEAdvertising::setAppearance(uint16_t appearance) {
m_advData.appearance = appearance;
} // setAppearance
void BLEAdvertising::setAdvertisementType(esp_ble_adv_type_t adv_type){
m_advParams.adv_type = adv_type;
} // setAdvertisementType
void BLEAdvertising::setMinInterval(uint16_t mininterval) {
m_advParams.adv_int_min = mininterval;
} // setMinInterval

View File

@ -52,6 +52,7 @@ public:
void start();
void stop();
void setAppearance(uint16_t appearance);
void setAdvertisementType(esp_ble_adv_type_t adv_type);
void setMaxInterval(uint16_t maxinterval);
void setMinInterval(uint16_t mininterval);
void setAdvertisementData(BLEAdvertisementData& advertisementData);
@ -76,4 +77,4 @@ private:
};
#endif /* CONFIG_BT_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEADVERTISING_H_ */
#endif /* COMPONENTS_CPP_UTILS_BLEADVERTISING_H_ */

View File

@ -32,14 +32,8 @@
#include "esp32-hal-bt.h"
#endif
#if defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEDevice";
#endif
/**
* Singletons for the BLEDevice.
@ -447,11 +441,26 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
* * ESP_PWR_LVL_P1
* * ESP_PWR_LVL_P4
* * ESP_PWR_LVL_P7
*
* The power types can be one of:
* * ESP_BLE_PWR_TYPE_CONN_HDL0
* * ESP_BLE_PWR_TYPE_CONN_HDL1
* * ESP_BLE_PWR_TYPE_CONN_HDL2
* * ESP_BLE_PWR_TYPE_CONN_HDL3
* * ESP_BLE_PWR_TYPE_CONN_HDL4
* * ESP_BLE_PWR_TYPE_CONN_HDL5
* * ESP_BLE_PWR_TYPE_CONN_HDL6
* * ESP_BLE_PWR_TYPE_CONN_HDL7
* * ESP_BLE_PWR_TYPE_CONN_HDL8
* * ESP_BLE_PWR_TYPE_ADV
* * ESP_BLE_PWR_TYPE_SCAN
* * ESP_BLE_PWR_TYPE_DEFAULT
* @param [in] powerType.
* @param [in] powerLevel.
*/
/* STATIC */ void BLEDevice::setPower(esp_power_level_t powerLevel) {
log_v(">> setPower: %d", powerLevel);
esp_err_t errRc = ::esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, powerLevel);
/* STATIC */ void BLEDevice::setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType) {
log_v(">> setPower: %d (type: %d)", powerLevel, powerType);
esp_err_t errRc = ::esp_ble_tx_power_set(powerType, powerLevel);
if (errRc != ESP_OK) {
log_e("esp_ble_tx_power_set: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
};
@ -490,7 +499,11 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
*/
void BLEDevice::whiteListAdd(BLEAddress address) {
log_v(">> whiteListAdd: %s", address.toString().c_str());
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry.
#ifdef ESP_IDF_VERSION_MAJOR
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! True to add an entry.
#else
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry.
#endif
if (errRc != ESP_OK) {
log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
@ -504,7 +517,11 @@ void BLEDevice::whiteListAdd(BLEAddress address) {
*/
void BLEDevice::whiteListRemove(BLEAddress address) {
log_v(">> whiteListRemove: %s", address.toString().c_str());
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry.
#ifdef ESP_IDF_VERSION_MAJOR
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! False to remove an entry.
#else
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry.
#endif
if (errRc != ESP_OK) {
log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
@ -569,6 +586,12 @@ void BLEDevice::startAdvertising() {
log_v("<< startAdvertising");
} // startAdvertising
void BLEDevice::stopAdvertising() {
log_v(">> stopAdvertising");
getAdvertising()->stop();
log_v("<< stopAdvertising");
} // stopAdvertising
/* multi connect support */
/* requires a little more work */
std::map<uint16_t, conn_status_t> BLEDevice::getPeerDevices(bool _client) {

View File

@ -37,7 +37,7 @@ public:
static BLEScan* getScan(); // Get the scan object
static std::string getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID); // Get the value of a characteristic of a service on a server.
static void init(std::string deviceName); // Initialize the local BLE environment.
static void setPower(esp_power_level_t powerLevel); // Set our power level.
static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT); // Set our power level.
static void setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value); // Set the value of a characteristic on a service on a server.
static std::string toString(); // Return a string representation of our device.
static void whiteListAdd(BLEAddress address); // Add an entry to the BLE white list.
@ -50,6 +50,7 @@ public:
/* move advertising to BLEDevice for saving ram and flash in beacons */
static BLEAdvertising* getAdvertising();
static void startAdvertising();
static void stopAdvertising();
static uint16_t m_appId;
/* multi connect */
static std::map<uint16_t, conn_status_t> getPeerDevices(bool client);

View File

@ -40,6 +40,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
m_pRemoteService = pRemoteService;
m_notifyCallback = nullptr;
m_rawData = nullptr;
m_auth = ESP_GATT_AUTH_REQ_NONE;
retrieveDescriptors(); // Get the descriptors for this characteristic
log_v("<< BLERemoteCharacteristic");
@ -389,6 +390,17 @@ uint8_t BLERemoteCharacteristic::readUInt8() {
return 0;
} // readUInt8
/**
* @brief Read a float value.
* @return the float value.
*/
float BLERemoteCharacteristic::readFloat() {
std::string value = readValue();
if (value.length() >= 4) {
return *(float*)(value.data());
}
return 0.0;
} // readFloat
/**
* @brief Read the value of the remote characteristic.
@ -412,7 +424,7 @@ std::string BLERemoteCharacteristic::readValue() {
m_pRemoteService->getClient()->getGattcIf(),
m_pRemoteService->getClient()->getConnId(), // The connection ID to the BLE server
getHandle(), // The handle of this characteristic
ESP_GATT_AUTH_REQ_NONE); // Security
m_auth); // Security
if (errRc != ESP_OK) {
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
@ -563,7 +575,7 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp
length,
data,
response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
ESP_GATT_AUTH_REQ_NONE
m_auth
);
if (errRc != ESP_OK) {
@ -584,4 +596,12 @@ uint8_t* BLERemoteCharacteristic::readRawData() {
return m_rawData;
}
/**
* @brief Set authentication request type for characteristic
* @param [in] auth Authentication request type.
*/
void BLERemoteCharacteristic::setAuth(esp_gatt_auth_req_t auth) {
m_auth = auth;
}
#endif /* CONFIG_BT_ENABLED */

View File

@ -45,12 +45,14 @@ public:
uint8_t readUInt8();
uint16_t readUInt16();
uint32_t readUInt32();
float readFloat();
void registerForNotify(notify_callback _callback, bool notifications = true);
void writeValue(uint8_t* data, size_t length, bool response = false);
void writeValue(std::string newValue, bool response = false);
void writeValue(uint8_t newValue, bool response = false);
std::string toString();
uint8_t* readRawData();
void setAuth(esp_gatt_auth_req_t auth);
private:
BLERemoteCharacteristic(uint16_t handle, BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService);
@ -68,6 +70,7 @@ private:
// Private properties
BLEUUID m_uuid;
esp_gatt_char_prop_t m_charProp;
esp_gatt_auth_req_t m_auth;
uint16_t m_handle;
BLERemoteService* m_pRemoteService;
FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");

View File

@ -19,6 +19,7 @@ BLERemoteDescriptor::BLERemoteDescriptor(
m_handle = handle;
m_uuid = uuid;
m_pRemoteCharacteristic = pRemoteCharacteristic;
m_auth = ESP_GATT_AUTH_REQ_NONE;
}
@ -65,7 +66,7 @@ std::string BLERemoteDescriptor::readValue() {
m_pRemoteCharacteristic->getRemoteService()->getClient()->getGattcIf(),
m_pRemoteCharacteristic->getRemoteService()->getClient()->getConnId(), // The connection ID to the BLE server
getHandle(), // The handle of this characteristic
ESP_GATT_AUTH_REQ_NONE); // Security
m_auth); // Security
if (errRc != ESP_OK) {
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
@ -143,7 +144,7 @@ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response
length, // Data length
data, // Data
response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP,
ESP_GATT_AUTH_REQ_NONE
m_auth
);
if (errRc != ESP_OK) {
log_e("esp_ble_gattc_write_char_descr: %d", errRc);
@ -171,5 +172,12 @@ void BLERemoteDescriptor::writeValue(uint8_t newValue, bool response) {
writeValue(&newValue, 1, response);
} // writeValue
/**
* @brief Set authentication request type for characteristic
* @param [in] auth Authentication request type.
*/
void BLERemoteDescriptor::setAuth(esp_gatt_auth_req_t auth) {
m_auth = auth;
}
#endif /* CONFIG_BT_ENABLED */

View File

@ -34,6 +34,7 @@ public:
void writeValue(uint8_t* data, size_t length, bool response = false);
void writeValue(std::string newValue, bool response = false);
void writeValue(uint8_t newValue, bool response = false);
void setAuth(esp_gatt_auth_req_t auth);
private:
@ -48,6 +49,7 @@ private:
std::string m_value; // Last received value of the descriptor.
BLERemoteCharacteristic* m_pRemoteCharacteristic; // Reference to the Remote characteristic of which this descriptor is associated.
FreeRTOS::Semaphore m_semaphoreReadDescrEvt = FreeRTOS::Semaphore("ReadDescrEvt");
esp_gatt_auth_req_t m_auth;
};

View File

@ -243,8 +243,8 @@ std::map<uint16_t, BLERemoteCharacteristic*>* BLERemoteService::getCharacteristi
/**
* @brief This function is designed to get characteristics map when we have multiple characteristics with the same UUID
*/
void BLERemoteService::getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>* pCharacteristicMap) {
pCharacteristicMap = &m_characteristicMapByHandle;
void BLERemoteService::getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>** pCharacteristicMap) {
*pCharacteristicMap = &m_characteristicMapByHandle;
} // Get the characteristics map.
/**

View File

@ -34,7 +34,7 @@ public:
BLERemoteCharacteristic* getCharacteristic(uint16_t uuid); // Get the specified characteristic reference.
std::map<std::string, BLERemoteCharacteristic*>* getCharacteristics();
std::map<uint16_t, BLERemoteCharacteristic*>* getCharacteristicsByHandle(); // Get the characteristics map.
void getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>* pCharacteristicMap);
void getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>** pCharacteristicMap);
BLEClient* getClient(void); // Get a reference to the client associated with this service.
uint16_t getHandle(); // Get the handle of this service.

View File

@ -186,7 +186,7 @@ void FreeRTOS::Semaphore::giveFromISR() {
* @return True if we took the semaphore.
*/
bool FreeRTOS::Semaphore::take(std::string owner) {
log_d("Semaphore taking: %s for %s", toString().c_str(), owner.c_str());
log_v("Semaphore taking: %s for %s", toString().c_str(), owner.c_str());
bool rc = false;
if (m_usePthreads) {
pthread_mutex_lock(&m_pthread_mutex);
@ -195,7 +195,7 @@ bool FreeRTOS::Semaphore::take(std::string owner) {
}
m_owner = owner;
if (rc) {
log_d("Semaphore taken: %s", toString().c_str());
log_v("Semaphore taken: %s", toString().c_str());
} else {
log_e("Semaphore NOT taken: %s", toString().c_str());
}
@ -257,7 +257,12 @@ void FreeRTOS::Semaphore::setName(std::string name) {
* @param [in] length The amount of storage to allocate for the ring buffer.
* @param [in] type The type of buffer. One of RINGBUF_TYPE_NOSPLIT, RINGBUF_TYPE_ALLOWSPLIT, RINGBUF_TYPE_BYTEBUF.
*/
Ringbuffer::Ringbuffer(size_t length, ringbuf_type_t type) {
#ifdef ESP_IDF_VERSION_MAJOR
Ringbuffer::Ringbuffer(size_t length, RingbufferType_t type)
#else
Ringbuffer::Ringbuffer(size_t length, ringbuf_type_t type)
#endif
{
m_handle = ::xRingbufferCreate(length, type);
} // Ringbuffer

View File

@ -60,7 +60,11 @@ public:
*/
class Ringbuffer {
public:
Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT);
#ifdef ESP_IDF_VERSION_MAJOR
Ringbuffer(size_t length, RingbufferType_t type = RINGBUF_TYPE_NOSPLIT);
#else
Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT);
#endif
~Ringbuffer();
void* receive(size_t* size, TickType_t wait = portMAX_DELAY);

View File

@ -0,0 +1,56 @@
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Victor Tchistiak - 2019
//
//This example demostrates master mode bluetooth connection and pin
//it creates a bridge between Serial and Classical Bluetooth (SPP)
//this is an extention of the SerialToSerialBT example by Evandro Copercini - 2018
//
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
String MACadd = "AA:BB:CC:11:22:33";
uint8_t address[6] = {0xAA, 0xBB, 0xCC, 0x11, 0x22, 0x33};
//uint8_t address[6] = {0x00, 0x1D, 0xA5, 0x02, 0xC3, 0x22};
String name = "OBDII";
const char *pin = "1234"; //<- standard pin would be provided by default
bool connected;
void setup() {
Serial.begin(115200);
//SerialBT.setPin(pin);
SerialBT.begin("ESP32test", true);
//SerialBT.setPin(pin);
Serial.println("The device started in master mode, make sure remote BT device is on!");
// connect(address) is fast (upto 10 secs max), connect(name) is slow (upto 30 secs max) as it needs
// to resolve name to address first, but it allows to connect to different devices with the same name.
// Set CoreDebugLevel to Info to view devices bluetooth address and device names
connected = SerialBT.connect(name);
//connected = SerialBT.connect(address);
if(connected) {
Serial.println("Connected Succesfully!");
} else {
while(!SerialBT.connected(10000)) {
Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
}
}
// disconnect() may take upto 10 secs max
if (SerialBT.disconnect()) {
Serial.println("Disconnected Succesfully!");
}
// this would reconnect to the name(will use address, if resolved) or address used with connect(name/address).
SerialBT.connect();
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(20);
}

View File

@ -0,0 +1,87 @@
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Victor Tchistiak - 2019
//
//This example demonstrates reading and removing paired devices stored on the ESP32 flash memory
//Sometimes you may find your ESP32 device could not connect to the remote device despite
//many successful connections earlier. This is most likely a result of client replacing your paired
//device info with new one from other device. The BT clients store connection info for paired devices,
//but it is limited to a few devices only. When new device pairs and number of stored devices is exceeded,
//one of the previously paired devices would be replaced with new one.
//The only remedy is to delete this saved bound device from your device flash memory
//and pair with the other device again.
//
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include"esp_gap_bt_api.h"
#include "esp_err.h"
#define REMOVE_BONDED_DEVICES 0 // <- Set to 0 to view all bonded devices addresses, set to 1 to remove
#define PAIR_MAX_DEVICES 20
uint8_t pairedDeviceBtAddr[PAIR_MAX_DEVICES][6];
char bda_str[18];
bool initBluetooth()
{
if(!btStart()) {
Serial.println("Failed to initialize controller");
return false;
}
if(esp_bluedroid_init() != ESP_OK) {
Serial.println("Failed to initialize bluedroid");
return false;
}
if(esp_bluedroid_enable() != ESP_OK) {
Serial.println("Failed to enable bluedroid");
return false;
}
return true;
}
char *bda2str(const uint8_t* bda, char *str, size_t size)
{
if (bda == NULL || str == NULL || size < 18) {
return NULL;
}
sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
return str;
}
void setup() {
Serial.begin(115200);
initBluetooth();
Serial.print("ESP32 bluetooth address: "); Serial.println(bda2str(esp_bt_dev_get_address(), bda_str, 18));
// Get the numbers of bonded/paired devices in the BT module
int count = esp_bt_gap_get_bond_device_num();
if(!count) {
Serial.println("No bonded device found.");
} else {
Serial.print("Bonded device count: "); Serial.println(count);
if(PAIR_MAX_DEVICES < count) {
count = PAIR_MAX_DEVICES;
Serial.print("Reset bonded device count: "); Serial.println(count);
}
esp_err_t tError = esp_bt_gap_get_bond_device_list(&count, pairedDeviceBtAddr);
if(ESP_OK == tError) {
for(int i = 0; i < count; i++) {
Serial.print("Found bonded device # "); Serial.print(i); Serial.print(" -> ");
Serial.println(bda2str(pairedDeviceBtAddr[i], bda_str, 18));
if(REMOVE_BONDED_DEVICES) {
esp_err_t tError = esp_bt_gap_remove_bond_device(pairedDeviceBtAddr[i]);
if(ESP_OK == tError) {
Serial.print("Removed bonded device # ");
} else {
Serial.print("Failed to remove bonded device # ");
}
Serial.println(i);
}
}
}
}
}
void loop() {}

398
libraries/BluetoothSerial/src/BluetoothSerial.cpp Normal file → Executable file
View File

@ -36,9 +36,7 @@
#include "esp_spp_api.h"
#include <esp_log.h>
#ifdef ARDUINO_ARCH_ESP32
#include "esp32-hal-log.h"
#endif
const char * _spp_server_name = "ESP32SPP";
@ -52,16 +50,84 @@ static TaskHandle_t _spp_task_handle = NULL;
static EventGroupHandle_t _spp_event_group = NULL;
static boolean secondConnectionAttempt;
static esp_spp_cb_t * custom_spp_callback = NULL;
static BluetoothSerialDataCb custom_data_callback = NULL;
#define INQ_LEN 0x10
#define INQ_NUM_RSPS 20
#define READY_TIMEOUT (10 * 1000)
#define SCAN_TIMEOUT (INQ_LEN * 2 * 1000)
static esp_bd_addr_t _peer_bd_addr;
static char _remote_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
static bool _isRemoteAddressSet;
static bool _isMaster;
static esp_bt_pin_code_t _pin_code;
static int _pin_len;
static bool _isPinSet;
static bool _enableSSP;
#define SPP_RUNNING 0x01
#define SPP_CONNECTED 0x02
#define SPP_CONGESTED 0x04
#define SPP_DISCONNECTED 0x08
typedef struct {
size_t len;
uint8_t data[];
} spp_packet_t;
#if (ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO)
static char *bda2str(esp_bd_addr_t bda, char *str, size_t size)
{
if (bda == NULL || str == NULL || size < 18) {
return NULL;
}
uint8_t *p = bda;
sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
p[0], p[1], p[2], p[3], p[4], p[5]);
return str;
}
#endif
static bool get_name_from_eir(uint8_t *eir, char *bdname, uint8_t *bdname_len)
{
if (!eir || !bdname || !bdname_len) {
return false;
}
uint8_t *rmt_bdname, rmt_bdname_len;
*bdname = *bdname_len = rmt_bdname_len = 0;
rmt_bdname = esp_bt_gap_resolve_eir_data(eir, ESP_BT_EIR_TYPE_CMPL_LOCAL_NAME, &rmt_bdname_len);
if (!rmt_bdname) {
rmt_bdname = esp_bt_gap_resolve_eir_data(eir, ESP_BT_EIR_TYPE_SHORT_LOCAL_NAME, &rmt_bdname_len);
}
if (rmt_bdname) {
rmt_bdname_len = rmt_bdname_len > ESP_BT_GAP_MAX_BDNAME_LEN ? ESP_BT_GAP_MAX_BDNAME_LEN : rmt_bdname_len;
memcpy(bdname, rmt_bdname, rmt_bdname_len);
bdname[rmt_bdname_len] = 0;
*bdname_len = rmt_bdname_len;
return true;
}
return false;
}
static bool btSetPin() {
esp_bt_pin_type_t pin_type;
if (_isPinSet) {
if (_pin_len) {
log_i("pin set");
pin_type = ESP_BT_PIN_TYPE_FIXED;
} else {
_isPinSet = false;
log_i("pin reset");
pin_type = ESP_BT_PIN_TYPE_VARIABLE; // pin_code would be ignored (default)
}
return (esp_bt_gap_set_pin(pin_type, _pin_len, _pin_code) == ESP_OK);
}
return false;
}
static esp_err_t _spp_queue_packet(uint8_t *data, size_t len){
if(!data || !len){
log_w("No data provided");
@ -87,7 +153,7 @@ static uint8_t _spp_tx_buffer[SPP_TX_MAX];
static uint16_t _spp_tx_buffer_len = 0;
static bool _spp_send_buffer(){
if((xEventGroupWaitBits(_spp_event_group, SPP_CONGESTED, pdFALSE, pdTRUE, portMAX_DELAY) & SPP_CONGESTED)){
if((xEventGroupWaitBits(_spp_event_group, SPP_CONGESTED, pdFALSE, pdTRUE, portMAX_DELAY) & SPP_CONGESTED) != 0){
esp_err_t err = esp_spp_write(_spp_client, _spp_tx_buffer_len, _spp_tx_buffer);
if(err != ESP_OK){
log_e("SPP Write Failed! [0x%X]", err);
@ -151,37 +217,45 @@ static void _spp_tx_task(void * arg){
_spp_task_handle = NULL;
}
static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
switch (event)
{
case ESP_SPP_INIT_EVT:
log_i("ESP_SPP_INIT_EVT");
#ifdef ESP_IDF_VERSION_MAJOR
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
#else
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, _spp_server_name);
#endif
if (!_isMaster) {
log_i("ESP_SPP_INIT_EVT: slave: start");
esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, _spp_server_name);
}
xEventGroupSetBits(_spp_event_group, SPP_RUNNING);
break;
case ESP_SPP_SRV_OPEN_EVT://Server connection open
log_i("ESP_SPP_SRV_OPEN_EVT");
if (!_spp_client){
_spp_client = param->open.handle;
} else {
secondConnectionAttempt = true;
esp_spp_disconnect(param->open.handle);
}
xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED);
xEventGroupSetBits(_spp_event_group, SPP_CONNECTED);
log_i("ESP_SPP_SRV_OPEN_EVT");
break;
case ESP_SPP_CLOSE_EVT://Client connection closed
log_i("ESP_SPP_CLOSE_EVT");
if(secondConnectionAttempt) {
secondConnectionAttempt = false;
} else {
_spp_client = 0;
}
xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED);
}
xEventGroupClearBits(_spp_event_group, SPP_CONNECTED);
log_i("ESP_SPP_CLOSE_EVT");
break;
case ESP_SPP_CONG_EVT://connection congestion status changed
@ -206,7 +280,9 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
//esp_log_buffer_hex("",param->data_ind.data,param->data_ind.len); //for low level debug
//ets_printf("r:%u\n", param->data_ind.len);
if (_spp_rx_queue != NULL){
if(custom_data_callback){
custom_data_callback(param->data_ind.data, param->data_ind.len);
} else if (_spp_rx_queue != NULL){
for (int i = 0; i < param->data_ind.len; i++){
if(xQueueSend(_spp_rx_queue, param->data_ind.data + i, (TickType_t)0) != pdTRUE){
log_e("RX Full! Discarding %u bytes", param->data_ind.len - i);
@ -216,25 +292,155 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
}
break;
//should maybe delete those.
case ESP_SPP_DISCOVERY_COMP_EVT://discovery complete
log_i("ESP_SPP_DISCOVERY_COMP_EVT");
if (param->disc_comp.status == ESP_SPP_SUCCESS) {
log_i("ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote");
esp_spp_connect(ESP_SPP_SEC_AUTHENTICATE, ESP_SPP_ROLE_MASTER, param->disc_comp.scn[0], _peer_bd_addr);
}
break;
case ESP_SPP_OPEN_EVT://Client connection open
log_i("ESP_SPP_OPEN_EVT");
if (!_spp_client){
_spp_client = param->open.handle;
} else {
secondConnectionAttempt = true;
esp_spp_disconnect(param->open.handle);
}
xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED);
xEventGroupSetBits(_spp_event_group, SPP_CONNECTED);
break;
case ESP_SPP_START_EVT://server started
log_i("ESP_SPP_START_EVT");
break;
case ESP_SPP_CL_INIT_EVT://client initiated a connection
log_i("ESP_SPP_CL_INIT_EVT");
break;
default:
break;
}
if(custom_spp_callback)(*custom_spp_callback)(event, param);
}
void BluetoothSerial::onData(BluetoothSerialDataCb cb){
custom_data_callback = cb;
}
static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
switch(event){
case ESP_BT_GAP_DISC_RES_EVT:
log_i("ESP_BT_GAP_DISC_RES_EVT");
#if (ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO)
char bda_str[18];
log_i("Scanned device: %s", bda2str(param->disc_res.bda, bda_str, 18));
#endif
for (int i = 0; i < param->disc_res.num_prop; i++) {
uint8_t peer_bdname_len;
char peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
switch(param->disc_res.prop[i].type) {
case ESP_BT_GAP_DEV_PROP_EIR:
if (get_name_from_eir((uint8_t*)param->disc_res.prop[i].val, peer_bdname, &peer_bdname_len)) {
log_i("ESP_BT_GAP_DISC_RES_EVT : EIR : %s : %d", peer_bdname, peer_bdname_len);
if (strlen(_remote_name) == peer_bdname_len
&& strncmp(peer_bdname, _remote_name, peer_bdname_len) == 0) {
log_v("ESP_BT_GAP_DISC_RES_EVT : SPP_START_DISCOVERY_EIR : %s", peer_bdname, peer_bdname_len);
_isRemoteAddressSet = true;
memcpy(_peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN);
esp_bt_gap_cancel_discovery();
esp_spp_start_discovery(_peer_bd_addr);
}
}
break;
case ESP_BT_GAP_DEV_PROP_BDNAME:
peer_bdname_len = param->disc_res.prop[i].len;
memcpy(peer_bdname, param->disc_res.prop[i].val, peer_bdname_len);
peer_bdname_len--; // len includes 0 terminator
log_v("ESP_BT_GAP_DISC_RES_EVT : BDNAME : %s : %d", peer_bdname, peer_bdname_len);
if (strlen(_remote_name) == peer_bdname_len
&& strncmp(peer_bdname, _remote_name, peer_bdname_len) == 0) {
log_i("ESP_BT_GAP_DISC_RES_EVT : SPP_START_DISCOVERY_BDNAME : %s", peer_bdname);
_isRemoteAddressSet = true;
memcpy(_peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN);
esp_bt_gap_cancel_discovery();
esp_spp_start_discovery(_peer_bd_addr);
}
break;
case ESP_BT_GAP_DEV_PROP_COD:
log_d("ESP_BT_GAP_DEV_PROP_COD");
break;
case ESP_BT_GAP_DEV_PROP_RSSI:
log_d("ESP_BT_GAP_DEV_PROP_RSSI");
break;
default:
break;
}
if (_isRemoteAddressSet)
break;
}
break;
case ESP_BT_GAP_DISC_STATE_CHANGED_EVT:
log_i("ESP_BT_GAP_DISC_STATE_CHANGED_EVT");
break;
case ESP_BT_GAP_RMT_SRVCS_EVT:
log_i( "ESP_BT_GAP_RMT_SRVCS_EVT");
break;
case ESP_BT_GAP_RMT_SRVC_REC_EVT:
log_i("ESP_BT_GAP_RMT_SRVC_REC_EVT");
break;
case ESP_BT_GAP_AUTH_CMPL_EVT:
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
log_v("authentication success: %s", param->auth_cmpl.device_name);
} else {
log_e("authentication failed, status:%d", param->auth_cmpl.stat);
}
break;
case ESP_BT_GAP_PIN_REQ_EVT:
// default pairing pins
log_i("ESP_BT_GAP_PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit);
if (param->pin_req.min_16_digit) {
log_i("Input pin code: 0000 0000 0000 0000");
esp_bt_pin_code_t pin_code;
memset(pin_code, '0', ESP_BT_PIN_CODE_LEN);
esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code);
} else {
log_i("Input pin code: 1234");
esp_bt_pin_code_t pin_code;
memcpy(pin_code, "1234", 4);
esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code);
}
break;
case ESP_BT_GAP_CFM_REQ_EVT:
log_i("ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
break;
case ESP_BT_GAP_KEY_NOTIF_EVT:
log_i("ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey);
break;
case ESP_BT_GAP_KEY_REQ_EVT:
log_i("ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
break;
default:
break;
}
}
static bool _init_bt(const char *deviceName)
{
if(!_spp_event_group){
@ -245,6 +451,7 @@ static bool _init_bt(const char *deviceName)
}
xEventGroupClearBits(_spp_event_group, 0xFFFFFF);
xEventGroupSetBits(_spp_event_group, SPP_CONGESTED);
xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED);
}
if (_spp_rx_queue == NULL){
_spp_rx_queue = xQueueCreate(RX_QUEUE_SIZE, sizeof(uint8_t)); //initialize the queue
@ -270,7 +477,7 @@ static bool _init_bt(const char *deviceName)
}
if(!_spp_task_handle){
xTaskCreate(_spp_tx_task, "spp_tx", 4096, NULL, 2, &_spp_task_handle);
xTaskCreatePinnedToCore(_spp_tx_task, "spp_tx", 4096, NULL, 2, &_spp_task_handle, 0);
if(!_spp_task_handle){
log_e("Network Event Task Start Failed!");
return false;
@ -297,6 +504,11 @@ static bool _init_bt(const char *deviceName)
}
}
if (_isMaster && esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) {
log_e("gap register failed");
return false;
}
if (esp_spp_register_callback(esp_spp_cb) != ESP_OK){
log_e("spp register failed");
return false;
@ -307,8 +519,24 @@ static bool _init_bt(const char *deviceName)
return false;
}
if (esp_bt_sleep_disable() != ESP_OK){
log_e("esp_bt_sleep_disable failed");
}
log_i("device name set");
esp_bt_dev_set_device_name(deviceName);
if (_isPinSet) {
btSetPin();
}
if (_enableSSP) {
log_i("Simple Secure Pairing");
esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
}
// the default BTA_DM_COD_LOUDSPEAKER does not work with the macOS BT stack
esp_bt_cod_t cod;
cod.major = 0b00001;
@ -318,7 +546,6 @@ static bool _init_bt(const char *deviceName)
log_e("set cod failed");
return false;
}
return true;
}
@ -361,6 +588,11 @@ static bool _stop_bt()
return true;
}
static bool waitForConnect(int timeout) {
TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS;
return (xEventGroupWaitBits(_spp_event_group, SPP_CONNECTED, pdFALSE, pdTRUE, xTicksToWait) & SPP_CONNECTED) != 0;
}
/*
* Serial Bluetooth Arduino
*
@ -376,8 +608,9 @@ BluetoothSerial::~BluetoothSerial(void)
_stop_bt();
}
bool BluetoothSerial::begin(String localName)
bool BluetoothSerial::begin(String localName, bool isMaster)
{
_isMaster = isMaster;
if (localName.length()){
local_name = localName;
}
@ -431,7 +664,11 @@ size_t BluetoothSerial::write(const uint8_t *buffer, size_t size)
void BluetoothSerial::flush()
{
while(read() >= 0){}
if (_spp_tx_queue != NULL){
while(uxQueueMessagesWaiting(_spp_tx_queue) > 0){
delay(5);
}
}
}
void BluetoothSerial::end()
@ -445,4 +682,137 @@ esp_err_t BluetoothSerial::register_callback(esp_spp_cb_t * callback)
return ESP_OK;
}
//Simple Secure Pairing
void BluetoothSerial::enableSSP() {
_enableSSP = true;
}
/*
* Set default parameters for Legacy Pairing
* Use fixed pin code
*/
bool BluetoothSerial::setPin(const char *pin) {
bool isEmpty = !(pin && *pin);
if (isEmpty && !_isPinSet) {
return true; // nothing to do
} else if (!isEmpty){
_pin_len = strlen(pin);
memcpy(_pin_code, pin, _pin_len);
} else {
_pin_len = 0; // resetting pin to none (default)
}
_pin_code[_pin_len] = 0;
_isPinSet = true;
if (isReady(false, READY_TIMEOUT)) {
btSetPin();
}
return true;
}
bool BluetoothSerial::connect(String remoteName)
{
if (!isReady(true, READY_TIMEOUT)) return false;
if (remoteName && remoteName.length() < 1) {
log_e("No remote name is provided");
return false;
}
disconnect();
_isRemoteAddressSet = false;
strncpy(_remote_name, remoteName.c_str(), ESP_BT_GAP_MAX_BDNAME_LEN);
_remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0;
log_i("master : remoteName");
// will first resolve name to address
#ifdef ESP_IDF_VERSION_MAJOR
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
#else
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
#endif
if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) {
return waitForConnect(SCAN_TIMEOUT);
}
return false;
}
bool BluetoothSerial::connect(uint8_t remoteAddress[])
{
if (!isReady(true, READY_TIMEOUT)) return false;
if (!remoteAddress) {
log_e("No remote address is provided");
return false;
}
disconnect();
_remote_name[0] = 0;
_isRemoteAddressSet = true;
memcpy(_peer_bd_addr, remoteAddress, ESP_BD_ADDR_LEN);
log_i("master : remoteAddress");
if (esp_spp_start_discovery(_peer_bd_addr) == ESP_OK) {
return waitForConnect(READY_TIMEOUT);
}
return false;
}
bool BluetoothSerial::connect()
{
if (!isReady(true, READY_TIMEOUT)) return false;
if (_isRemoteAddressSet){
disconnect();
// use resolved or set address first
log_i("master : remoteAddress");
if (esp_spp_start_discovery(_peer_bd_addr) == ESP_OK) {
return waitForConnect(READY_TIMEOUT);
}
return false;
} else if (_remote_name[0]) {
disconnect();
log_i("master : remoteName");
// will resolve name to address first - it may take a while
#ifdef ESP_IDF_VERSION_MAJOR
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
#else
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
#endif
if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) {
return waitForConnect(SCAN_TIMEOUT);
}
return false;
}
log_e("Neither Remote name nor address was provided");
return false;
}
bool BluetoothSerial::disconnect() {
if (_spp_client) {
flush();
log_i("disconnecting");
if (esp_spp_disconnect(_spp_client) == ESP_OK) {
TickType_t xTicksToWait = READY_TIMEOUT / portTICK_PERIOD_MS;
return (xEventGroupWaitBits(_spp_event_group, SPP_DISCONNECTED, pdFALSE, pdTRUE, xTicksToWait) & SPP_DISCONNECTED) != 0;
}
}
return false;
}
bool BluetoothSerial::unpairDevice(uint8_t remoteAddress[]) {
if (isReady(false, READY_TIMEOUT)) {
log_i("removing bonded device");
return (esp_bt_gap_remove_bond_device(remoteAddress) == ESP_OK);
}
return false;
}
bool BluetoothSerial::connected(int timeout) {
return waitForConnect(timeout);
}
bool BluetoothSerial::isReady(bool checkMaster, int timeout) {
if (checkMaster && !_isMaster) {
log_e("Master mode is not active. Call begin(localName, true) to enable Master mode");
return false;
}
if (!btStarted()) {
log_e("BT is not initialized. Call begin() first");
return false;
}
TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS;
return (xEventGroupWaitBits(_spp_event_group, SPP_RUNNING, pdFALSE, pdTRUE, xTicksToWait) & SPP_RUNNING) != 0;
}
#endif

16
libraries/BluetoothSerial/src/BluetoothSerial.h Normal file → Executable file
View File

@ -22,6 +22,9 @@
#include "Arduino.h"
#include "Stream.h"
#include <esp_spp_api.h>
#include <functional>
typedef std::function<void(const uint8_t *buffer, size_t size)> BluetoothSerialDataCb;
class BluetoothSerial: public Stream
{
@ -30,7 +33,7 @@ class BluetoothSerial: public Stream
BluetoothSerial(void);
~BluetoothSerial(void);
bool begin(String localName=String());
bool begin(String localName=String(), bool isMaster=false);
int available(void);
int peek(void);
bool hasClient(void);
@ -39,8 +42,19 @@ class BluetoothSerial: public Stream
size_t write(const uint8_t *buffer, size_t size);
void flush();
void end(void);
void onData(BluetoothSerialDataCb cb);
esp_err_t register_callback(esp_spp_cb_t * callback);
void enableSSP();
bool setPin(const char *pin);
bool connect(String remoteName);
bool connect(uint8_t remoteAddress[]);
bool connect();
bool connected(int timeout=0);
bool isReady(bool checkMaster=false, int timeout=0);
bool disconnect();
bool unpairDevice(uint8_t remoteAddress[]);
private:
String local_name;

View File

@ -11,7 +11,9 @@ String responseHTML = ""
"<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
"be redirected here.</p></body></html>";
void setup() {
void setup() {
WiFi.disconnect(); //added to start with the wifi off, avoid crashing
WiFi.mode(WIFI_OFF); //added to start with the wifi off, avoid crashing
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("DNSServer CaptivePortal example");

View File

@ -52,10 +52,10 @@ void setup() {
Serial.println("------------------------------------\n");
// Clear variables
name = '\0';
rname[0] = '\0';
height = 0;
age = 0;
Serial.print("name: "); Serial.println(name);
Serial.print("name: "); Serial.println(rname);
Serial.print("height: "); Serial.println(height);
Serial.print("age: "); Serial.println(age);
Serial.println("------------------------------------\n");

View File

@ -2,16 +2,18 @@
#include <WiFi.h>
//
// WARNING!!! Make sure that you have either selected ESP32 Wrover Module,
// or another board which has PSRAM enabled
// WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
// Ensure ESP32 Wrover Module or other board with PSRAM is selected
// Partial images will be transmitted if image exceeds buffer size
//
// Select camera model
#define CAMERA_MODEL_WROVER_KIT
//#define CAMERA_MODEL_ESP_EYE
//#define CAMERA_MODEL_M5STACK_PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE
//#define CAMERA_MODEL_AI_THINKER
#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
//#define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
#include "camera_pins.h"
@ -46,7 +48,9 @@ void setup() {
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
//init with high specs to pre-allocate larger buffers
// if PSRAM IC present, init with UXGA resolution and higher JPEG quality
// for larger pre-allocated frame buffer.
if(psramFound()){
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 10;
@ -70,13 +74,13 @@ void setup() {
}
sensor_t * s = esp_camera_sensor_get();
//initial sensors are flipped vertically and colors are a bit saturated
// initial sensors are flipped vertically and colors are a bit saturated
if (s->id.PID == OV3660_PID) {
s->set_vflip(s, 1);//flip it back
s->set_brightness(s, 1);//up the blightness just a bit
s->set_saturation(s, -2);//lower the saturation
s->set_vflip(s, 1); // flip it back
s->set_brightness(s, 1); // up the brightness just a bit
s->set_saturation(s, -2); // lower the saturation
}
//drop down frame size for higher initial frame rate
// drop down frame size for higher initial frame rate
s->set_framesize(s, FRAMESIZE_QVGA);
#if defined(CAMERA_MODEL_M5STACK_WIDE)

View File

@ -56,11 +56,11 @@ static ra_filter_t ra_filter;
httpd_handle_t stream_httpd = NULL;
httpd_handle_t camera_httpd = NULL;
static mtmn_config_t mtmn_config = {0};
static mtmn_config_t mtmn_config;
static int8_t detection_enabled = 0;
static int8_t recognition_enabled = 0;
static int8_t is_enrolling = 0;
static face_id_list id_list = {0};
static face_id_list id_list;
static ra_filter_t * ra_filter_init(ra_filter_t * filter, size_t sample_size){
memset(filter, 0, sizeof(ra_filter_t));

View File

@ -94,6 +94,25 @@
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
#elif defined(CAMERA_MODEL_TTGO_T_JOURNAL)
#define PWDN_GPIO_NUM 0
#define RESET_GPIO_NUM 15
#define XCLK_GPIO_NUM 27
#define SIOD_GPIO_NUM 25
#define SIOC_GPIO_NUM 23
#define Y9_GPIO_NUM 19
#define Y8_GPIO_NUM 36
#define Y7_GPIO_NUM 18
#define Y6_GPIO_NUM 39
#define Y5_GPIO_NUM 5
#define Y4_GPIO_NUM 34
#define Y3_GPIO_NUM 35
#define Y2_GPIO_NUM 17
#define VSYNC_GPIO_NUM 22
#define HREF_GPIO_NUM 26
#define PCLK_GPIO_NUM 21
#else
#error "Camera model not selected"
#endif

View File

@ -12,7 +12,15 @@
* Evandro Luis Copercini - 2017
*/
#include <rom/rtc.h>
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "esp32/rom/rtc.h"
#else
#error Target CONFIG_IDF_TARGET is not supported
#endif
#else // ESP32 Before IDF 4.0
#include "rom/rtc.h"
#endif
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */

View File

@ -52,6 +52,7 @@ void readFile(fs::FS &fs, const char * path){
while(file.available()){
Serial.write(file.read());
}
file.close();
}
void writeFile(fs::FS &fs, const char * path, const char * message){
@ -65,8 +66,9 @@ void writeFile(fs::FS &fs, const char * path, const char * message){
if(file.print(message)){
Serial.println("- file written");
} else {
Serial.println("- frite failed");
Serial.println("- write failed");
}
file.close();
}
void appendFile(fs::FS &fs, const char * path, const char * message){
@ -82,6 +84,7 @@ void appendFile(fs::FS &fs, const char * path, const char * message){
} else {
Serial.println("- append failed");
}
file.close();
}
void renameFile(fs::FS &fs, const char * path1, const char * path2){

View File

@ -45,8 +45,7 @@ void setup() {
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); //set config settings to default
esp_wifi_sta_wpa2_ent_enable(&config); //set config settings to enable function
esp_wifi_sta_wpa2_ent_enable();
WiFi.begin(ssid); //connect to wifi
while (WiFi.status() != WL_CONNECTED) {
delay(500);

View File

@ -910,7 +910,7 @@ void HTTPClient::addHeader(const String& name, const String& value, bool first,
if (replace) {
int headerStart = _headers.indexOf(headerLine);
if (headerStart != -1) {
if (headerStart != -1 && (headerStart == 0 || _headers[headerStart - 1] == '\n')) {
int headerEnd = _headers.indexOf('\n', headerStart);
_headers = _headers.substring(0, headerStart) + _headers.substring(headerEnd + 1);
}
@ -924,7 +924,6 @@ void HTTPClient::addHeader(const String& name, const String& value, bool first,
_headers += headerLine;
}
}
}
void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount)

95
libraries/README.md Normal file
View File

@ -0,0 +1,95 @@
# ESP32 Libraries
arduino-esp32 includes libraries for Arduino compatibility along with some object wrappers around hardware specific devices. Examples are included in the examples folder under each library folder. The ESP32 includes additional examples which need no special drivers.
### ArduinoOTA
Over The Air firmware update daemon. Use espota.py to upload to the device.
### AsyncUDP
Asynchronous task driven UDP datagram client/server
### AzureIoT
Library to interact with Microsoft Azure IoT services
### BLE
Bluetooth Low Energy v4.2 client/server framework
### BluetoothSerial
Serial to Bluetooth redirection server
### DNSServer
A basic UDP DNS daemon (includes captive portal demo)
### EEPROM
Arduino compatibility for EEPROM (using flash)
### ESP32
Additional examples
* AnalogOut
* Camera
* ChipID
* DeepSleep
* ESPNow
* FreeRTOS
* GPIO
* HallSensor
* I2S
* ResetReason
* RMT
* Time
* Timer
* Touch
### ESPmDNS
mDNS service advertising
### FFat
FAT indexed filesystem on SPI flash
### FS
Filesystem virtualization framework
### HTTPClient
A simple HTTP client, compatible with WiFiClientSecure
### HTTPUpdate
Download a firmware update from HTTPd and apply it using Update
### NetBIOS
NetBIOS name advertiser
### Preferences
Flash keystore using ESP32 NVS
### SD
Secure Digital card filesystem using SPI access
### SD_MMC
Secure Digital card filesystem using 4-lane access
### SimpleBLE
Minimal BLE advertiser
### SPI
Arduino compatible Serial Peripheral Interface driver (master only)
### SPIFFS
SPI Flash Filesystem (see [spiffs-plugin](https://github.com/me-no-dev/arduino-esp32fs-plugin) to upload to device)
### Ticker
A timer to call functions on an interval
### Update
Sketch Update using ESP32 OTA functionality
### WebServer
A simple HTTP daemon
### WiFi
Arduino compatible WiFi driver (includes Ethernet driver)
### WiFiClientSecure
Arduino compatible WiFi client object using embedded encryption
### Wire
Arduino compatible I2C driver (master only)

View File

@ -12,10 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "sd_diskio.h"
#include "esp_system.h"
extern "C" {
#include "diskio.h"
#include "ffconf.h"
#include "ff.h"
#include "diskio.h"
#ifdef ESP_IDF_VERSION_MAJOR
#include "diskio_impl.h"
#endif
//#include "esp_vfs.h"
#include "esp_vfs_fat.h"
char CRC7(const char* data, int length);

View File

@ -15,6 +15,30 @@
*/
#include <SPI.h>
// Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus
#ifdef ALTERNATE_PINS
#define VSPI_MISO 2
#define VSPI_MOSI 4
#define VSPI_SCLK 0
#define VSPI_SS 33
#define HSPI_MISO 26
#define HSPI_MOSI 27
#define HSPI_SCLK 25
#define HSPI_SS 32
#else
#define VSPI_MISO MISO
#define VSPI_MOSI MOSI
#define VSPI_SCLK SCK
#define VSPI_SS SS
#define HSPI_MISO 12
#define HSPI_MOSI 13
#define HSPI_SCLK 14
#define HSPI_SS 15
#endif
static const int spiClk = 1000000; // 1 MHz
//uninitalised pointers to SPI objects
@ -28,22 +52,28 @@ void setup() {
//clock miso mosi ss
#ifndef ALTERNATE_PINS
//initialise vspi with default pins
//SCLK = 18, MISO = 19, MOSI = 23, SS = 5
vspi->begin();
#else
//alternatively route through GPIO pins of your choice
//hspi->begin(0, 2, 4, 33); //SCLK, MISO, MOSI, SS
vspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS
#endif
#ifndef ALTERNATE_PINS
//initialise hspi with default pins
//SCLK = 14, MISO = 12, MOSI = 13, SS = 15
hspi->begin();
hspi->begin();
#else
//alternatively route through GPIO pins
//hspi->begin(25, 26, 27, 32); //SCLK, MISO, MOSI, SS
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS); //SCLK, MISO, MOSI, SS
#endif
//set up slave select pins as outputs as the Arduino API
//doesn't handle automatically pulling SS low
pinMode(5, OUTPUT); //VSPI SS
pinMode(15, OUTPUT); //HSPI SS
pinMode(VSPI_SS, OUTPUT); //VSPI SS
pinMode(HSPI_SS, OUTPUT); //HSPI SS
}
@ -60,9 +90,9 @@ void vspiCommand() {
//use it as you would the regular arduino SPI API
vspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(5, LOW); //pull SS slow to prep other end for transfer
digitalWrite(VSPI_SS, LOW); //pull SS slow to prep other end for transfer
vspi->transfer(data);
digitalWrite(5, HIGH); //pull ss high to signify end of data transfer
digitalWrite(VSPI_SS, HIGH); //pull ss high to signify end of data transfer
vspi->endTransaction();
}
@ -70,8 +100,8 @@ void hspiCommand() {
byte stuff = 0b11001100;
hspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(15, LOW);
digitalWrite(HSPI_SS, LOW);
hspi->transfer(stuff);
digitalWrite(15, HIGH);
digitalWrite(HSPI_SS, HIGH);
hspi->endTransaction();
}

View File

@ -238,7 +238,7 @@ void SPIClass::writePixels(const void * data, uint32_t size)
* @param out uint8_t * output buffer. can be NULL for Write Only operation
* @param size uint32_t
*/
void SPIClass::transferBytes(uint8_t * data, uint8_t * out, uint32_t size)
void SPIClass::transferBytes(const uint8_t * data, uint8_t * out, uint32_t size)
{
if(_inTransaction){
return spiTransferBytesNL(_spi, data, out, size);
@ -251,7 +251,7 @@ void SPIClass::transferBytes(uint8_t * data, uint8_t * out, uint32_t size)
* @param size uint8_t max for size is 64Byte
* @param repeat uint32_t
*/
void SPIClass::writePattern(uint8_t * data, uint8_t size, uint32_t repeat)
void SPIClass::writePattern(const uint8_t * data, uint8_t size, uint32_t repeat)
{
if(size > 64) {
return; //max Hardware FIFO
@ -272,12 +272,12 @@ void SPIClass::writePattern(uint8_t * data, uint8_t size, uint32_t repeat)
}
}
void SPIClass::writePattern_(uint8_t * data, uint8_t size, uint8_t repeat)
void SPIClass::writePattern_(const uint8_t * data, uint8_t size, uint8_t repeat)
{
uint8_t bytes = (size * repeat);
uint8_t buffer[64];
uint8_t * bufferPtr = &buffer[0];
uint8_t * dataPtr;
const uint8_t * dataPtr;
uint8_t dataSize = bytes;
for(uint8_t i = 0; i < repeat; i++) {
dataSize = size;

View File

@ -48,7 +48,7 @@ private:
uint32_t _div;
uint32_t _freq;
bool _inTransaction;
void writePattern_(uint8_t * data, uint8_t size, uint8_t repeat);
void writePattern_(const uint8_t * data, uint8_t size, uint8_t repeat);
public:
SPIClass(uint8_t spi_bus=HSPI);
@ -70,7 +70,7 @@ public:
uint16_t transfer16(uint16_t data);
uint32_t transfer32(uint32_t data);
void transferBytes(uint8_t * data, uint8_t * out, uint32_t size);
void transferBytes(const uint8_t * data, uint8_t * out, uint32_t size);
void transferBits(uint32_t data, uint32_t * out, uint8_t bits);
void write(uint8_t data);
@ -78,7 +78,7 @@ public:
void write32(uint32_t data);
void writeBytes(const uint8_t * data, uint32_t size);
void writePixels(const void * data, uint32_t size);//ili9341 compatible
void writePattern(uint8_t * data, uint8_t size, uint32_t repeat);
void writePattern(const uint8_t * data, uint8_t size, uint32_t repeat);
spi_t * bus(){ return _spi; }
};

View File

@ -50,6 +50,7 @@ void readFile(fs::FS &fs, const char * path){
while(file.available()){
Serial.write(file.read());
}
file.close();
}
void writeFile(fs::FS &fs, const char * path, const char * message){
@ -63,8 +64,9 @@ void writeFile(fs::FS &fs, const char * path, const char * message){
if(file.print(message)){
Serial.println("- file written");
} else {
Serial.println("- frite failed");
Serial.println("- write failed");
}
file.close();
}
void appendFile(fs::FS &fs, const char * path, const char * message){
@ -80,6 +82,7 @@ void appendFile(fs::FS &fs, const char * path, const char * message){
} else {
Serial.println("- append failed");
}
file.close();
}
void renameFile(fs::FS &fs, const char * path1, const char * path2){

View File

@ -3,6 +3,9 @@
#include <WebServer.h>
#include <ESPmDNS.h>
#include <uri/UriBraces.h>
#include <uri/UriRegex.h>
const char *ssid = "........";
const char *password = "........";
@ -33,12 +36,12 @@ void setup(void) {
server.send(200, "text/plain", "hello from esp32!");
});
server.on("/users/{}", []() {
server.on(UriBraces("/users/{}"), []() {
String user = server.pathArg(0);
server.send(200, "text/plain", "User: '" + user + "'");
});
server.on("/users/{}/devices/{}", []() {
server.on(UriRegex("^\\/users\\/([0-9]+)\\/devices\\/([0-9]+)$"), []() {
String user = server.pathArg(0);
String device = server.pathArg(1);
server.send(200, "text/plain", "User: '" + user + "' and Device: '" + device + "'");

View File

@ -0,0 +1,28 @@
#ifndef URI_H
#define URI_H
#include <Arduino.h>
#include <vector>
class Uri {
protected:
const String _uri;
public:
Uri(const char *uri) : _uri(uri) {}
Uri(const String &uri) : _uri(uri) {}
virtual ~Uri() {}
virtual Uri* clone() const {
return new Uri(_uri);
};
virtual void initPathArgs(__attribute__((unused)) std::vector<String> &pathArgs) {}
virtual bool canHandle(const String &requestUri, __attribute__((unused)) std::vector<String> &pathArgs) {
return _uri == requestUri;
}
};
#endif

View File

@ -33,7 +33,7 @@
static const char AUTHORIZATION_HEADER[] = "Authorization";
static const char qop_auth[] = "qop=auth";
static const char qop_auth[] = "qop=\"auth\"";
static const char WWW_Authenticate[] = "WWW-Authenticate";
static const char Content_Length[] = "Content-Length";
@ -161,17 +161,17 @@ bool WebServer::authenticate(const char * username, const char * password){
} else if(authReq.startsWith(F("Digest"))) {
authReq = authReq.substring(7);
log_v("%s", authReq.c_str());
String _username = _extractParam(authReq,F("username=\""));
String _username = _extractParam(authReq,F("username=\""),'\"');
if(!_username.length() || _username != String(username)) {
authReq = "";
return false;
}
// extracting required parameters for RFC 2069 simpler Digest
String _realm = _extractParam(authReq, F("realm=\""));
String _nonce = _extractParam(authReq, F("nonce=\""));
String _uri = _extractParam(authReq, F("uri=\""));
String _response = _extractParam(authReq, F("response=\""));
String _opaque = _extractParam(authReq, F("opaque=\""));
String _realm = _extractParam(authReq, F("realm=\""),'\"');
String _nonce = _extractParam(authReq, F("nonce=\""),'\"');
String _uri = _extractParam(authReq, F("uri=\""),'\"');
String _response = _extractParam(authReq, F("response=\""),'\"');
String _opaque = _extractParam(authReq, F("opaque=\""),'\"');
if((!_realm.length()) || (!_nonce.length()) || (!_uri.length()) || (!_response.length()) || (!_opaque.length())) {
authReq = "";
@ -185,7 +185,7 @@ bool WebServer::authenticate(const char * username, const char * password){
String _nc,_cnonce;
if(authReq.indexOf(FPSTR(qop_auth)) != -1) {
_nc = _extractParam(authReq, F("nc="), ',');
_cnonce = _extractParam(authReq, F("cnonce=\""));
_cnonce = _extractParam(authReq, F("cnonce=\""),'\"');
}
String _H1 = md5str(String(username) + ':' + _realm + ':' + String(password));
log_v("Hash of user:realm:pass=%s", _H1.c_str());
@ -245,15 +245,15 @@ void WebServer::requestAuthentication(HTTPAuthMethod mode, const char* realm, co
send(401, String(FPSTR(mimeTable[html].mimeType)), authFailMsg);
}
void WebServer::on(const String &uri, WebServer::THandlerFunction handler) {
void WebServer::on(const Uri &uri, WebServer::THandlerFunction handler) {
on(uri, HTTP_ANY, handler);
}
void WebServer::on(const String &uri, HTTPMethod method, WebServer::THandlerFunction fn) {
void WebServer::on(const Uri &uri, HTTPMethod method, WebServer::THandlerFunction fn) {
on(uri, method, fn, _fileUploadHandler);
}
void WebServer::on(const String &uri, HTTPMethod method, WebServer::THandlerFunction fn, WebServer::THandlerFunction ufn) {
void WebServer::on(const Uri &uri, HTTPMethod method, WebServer::THandlerFunction fn, WebServer::THandlerFunction ufn) {
_addRequestHandler(new FunctionRequestHandler(fn, ufn, uri, method));
}

View File

@ -28,6 +28,7 @@
#include <memory>
#include <WiFi.h>
#include "HTTP_Method.h"
#include "Uri.h"
enum HTTPUploadStatus { UPLOAD_FILE_START, UPLOAD_FILE_WRITE, UPLOAD_FILE_END,
UPLOAD_FILE_ABORTED };
@ -84,9 +85,9 @@ public:
void requestAuthentication(HTTPAuthMethod mode = BASIC_AUTH, const char* realm = NULL, const String& authFailMsg = String("") );
typedef std::function<void(void)> THandlerFunction;
void on(const String &uri, THandlerFunction handler);
void on(const String &uri, HTTPMethod method, THandlerFunction fn);
void on(const String &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn);
void on(const Uri &uri, THandlerFunction handler);
void on(const Uri &uri, HTTPMethod method, THandlerFunction fn);
void on(const Uri &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn);
void addHandler(RequestHandler* handler);
void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL );
void onNotFound(THandlerFunction fn); //called when handler is not assigned

View File

@ -4,66 +4,30 @@
#include "RequestHandler.h"
#include "mimetable.h"
#include "WString.h"
#include "Uri.h"
using namespace mime;
class FunctionRequestHandler : public RequestHandler {
public:
FunctionRequestHandler(WebServer::THandlerFunction fn, WebServer::THandlerFunction ufn, const String &uri, HTTPMethod method)
FunctionRequestHandler(WebServer::THandlerFunction fn, WebServer::THandlerFunction ufn, const Uri &uri, HTTPMethod method)
: _fn(fn)
, _ufn(ufn)
, _uri(uri)
, _uri(uri.clone())
, _method(method)
{
int numParams = 0, start = 0;
do {
start = _uri.indexOf("{}", start);
if (start > 0) {
numParams++;
start += 2;
}
} while (start > 0);
pathArgs.resize(numParams);
_uri->initPathArgs(pathArgs);
}
~FunctionRequestHandler() {
delete _uri;
}
bool canHandle(HTTPMethod requestMethod, String requestUri) override {
if (_method != HTTP_ANY && _method != requestMethod)
return false;
if (_uri == requestUri)
return true;
size_t uriLength = _uri.length();
unsigned int pathArgIndex = 0;
unsigned int requestUriIndex = 0;
for (unsigned int i = 0; i < uriLength; i++, requestUriIndex++) {
char uriChar = _uri[i];
char requestUriChar = requestUri[requestUriIndex];
if (uriChar == requestUriChar)
continue;
if (uriChar != '{')
return false;
i += 2; // index of char after '}'
if (i >= uriLength) {
// there is no char after '}'
pathArgs[pathArgIndex] = requestUri.substring(requestUriIndex);
return pathArgs[pathArgIndex].indexOf("/") == -1; // path argument may not contain a '/'
}
else
{
char charEnd = _uri[i];
int uriIndex = requestUri.indexOf(charEnd, requestUriIndex);
if (uriIndex < 0)
return false;
pathArgs[pathArgIndex] = requestUri.substring(requestUriIndex, uriIndex);
requestUriIndex = (unsigned int) uriIndex;
}
pathArgIndex++;
}
return requestUriIndex >= requestUri.length();
return _uri->canHandle(requestUri, pathArgs);
}
bool canUpload(String requestUri) override {
@ -92,7 +56,7 @@ public:
protected:
WebServer::THandlerFunction _fn;
WebServer::THandlerFunction _ufn;
String _uri;
Uri *_uri;
HTTPMethod _method;
};

View File

@ -0,0 +1,66 @@
#ifndef URI_BRACES_H
#define URI_BRACES_H
#include "Uri.h"
class UriBraces : public Uri {
public:
explicit UriBraces(const char *uri) : Uri(uri) {};
explicit UriBraces(const String &uri) : Uri(uri) {};
Uri* clone() const override final {
return new UriBraces(_uri);
};
void initPathArgs(std::vector<String> &pathArgs) override final {
int numParams = 0, start = 0;
do {
start = _uri.indexOf("{}", start);
if (start > 0) {
numParams++;
start += 2;
}
} while (start > 0);
pathArgs.resize(numParams);
}
bool canHandle(const String &requestUri, std::vector<String> &pathArgs) override final {
if (Uri::canHandle(requestUri, pathArgs))
return true;
size_t uriLength = _uri.length();
unsigned int pathArgIndex = 0;
unsigned int requestUriIndex = 0;
for (unsigned int i = 0; i < uriLength; i++, requestUriIndex++) {
char uriChar = _uri[i];
char requestUriChar = requestUri[requestUriIndex];
if (uriChar == requestUriChar)
continue;
if (uriChar != '{')
return false;
i += 2; // index of char after '}'
if (i >= uriLength) {
// there is no char after '}'
pathArgs[pathArgIndex] = requestUri.substring(requestUriIndex);
return pathArgs[pathArgIndex].indexOf("/") == -1; // path argument may not contain a '/'
}
else
{
char charEnd = _uri[i];
int uriIndex = requestUri.indexOf(charEnd, requestUriIndex);
if (uriIndex < 0)
return false;
pathArgs[pathArgIndex] = requestUri.substring(requestUriIndex, uriIndex);
requestUriIndex = (unsigned int) uriIndex;
}
pathArgIndex++;
}
return requestUriIndex >= requestUri.length();
}
};
#endif

View File

@ -0,0 +1,22 @@
#ifndef URI_GLOB_H
#define URI_GLOB_H
#include "Uri.h"
#include <fnmatch.h>
class UriGlob : public Uri {
public:
explicit UriGlob(const char *uri) : Uri(uri) {};
explicit UriGlob(const String &uri) : Uri(uri) {};
Uri* clone() const override final {
return new UriGlob(_uri);
};
bool canHandle(const String &requestUri, __attribute__((unused)) std::vector<String> &pathArgs) override final {
return fnmatch(_uri.c_str(), requestUri.c_str(), 0) == 0;
}
};
#endif

View File

@ -0,0 +1,44 @@
#ifndef URI_REGEX_H
#define URI_REGEX_H
#include "Uri.h"
#include <regex>
class UriRegex : public Uri {
public:
explicit UriRegex(const char *uri) : Uri(uri) {};
explicit UriRegex(const String &uri) : Uri(uri) {};
Uri* clone() const override final {
return new UriRegex(_uri);
};
void initPathArgs(std::vector<String> &pathArgs) override final {
std::regex rgx((_uri + "|").c_str());
std::smatch matches;
std::string s{""};
std::regex_search(s, matches, rgx);
pathArgs.resize(matches.size() - 1);
}
bool canHandle(const String &requestUri, std::vector<String> &pathArgs) override final {
if (Uri::canHandle(requestUri, pathArgs))
return true;
unsigned int pathArgIndex = 0;
std::regex rgx(_uri.c_str());
std::smatch matches;
std::string s(requestUri.c_str());
if (std::regex_search(s, matches, rgx)) {
for (size_t i = 1; i < matches.size(); ++i) { // skip first
pathArgs[pathArgIndex] = String(matches[i].str().c_str());
pathArgIndex++;
}
return true;
}
return false;
}
};
#endif

View File

@ -1,103 +0,0 @@
/*
This sketch shows how to configure different external or internal clock sources for the Ethernet PHY
*/
#include <ETH.h>
/*
* ETH_CLOCK_GPIO0_IN - default: external clock from crystal oscillator
* ETH_CLOCK_GPIO0_OUT - 50MHz clock from internal APLL output on GPIO0 - possibly an inverter is needed for LAN8720
* ETH_CLOCK_GPIO16_OUT - 50MHz clock from internal APLL output on GPIO16 - possibly an inverter is needed for LAN8720
* ETH_CLOCK_GPIO17_OUT - 50MHz clock from internal APLL inverted output on GPIO17 - tested with LAN8720
*/
#ifdef ETH_CLK_MODE
#undef ETH_CLK_MODE
#endif
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
#define ETH_POWER_PIN -1
// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_TYPE ETH_PHY_LAN8720
// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_ADDR 0
// Pin# of the I²C clock signal for the Ethernet PHY
#define ETH_MDC_PIN 15
// Pin# of the I²C IO signal for the Ethernet PHY
#define ETH_MDIO_PIN 2
static bool eth_connected = false;
void WiFiEvent(WiFiEvent_t event) {
switch (event) {
case SYSTEM_EVENT_ETH_START:
Serial.println("ETH Started");
//set eth hostname here
ETH.setHostname("esp32-ethernet");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Serial.print("ETH MAC: ");
Serial.print(ETH.macAddress());
Serial.print(", IPv4: ");
Serial.print(ETH.localIP());
if (ETH.fullDuplex()) {
Serial.print(", FULL_DUPLEX");
}
Serial.print(", ");
Serial.print(ETH.linkSpeed());
Serial.println("Mbps");
eth_connected = true;
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case SYSTEM_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
void testClient(const char * host, uint16_t port) {
Serial.print("\nconnecting to ");
Serial.println(host);
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
while (client.connected() && !client.available());
while (client.available()) {
Serial.write(client.read());
}
Serial.println("closing connection\n");
client.stop();
}
void setup() {
Serial.begin(115200);
WiFi.onEvent(WiFiEvent);
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
}
void loop() {
if (eth_connected) {
testClient("google.com", 80);
}
delay(10000);
}

View File

@ -31,7 +31,6 @@ WPS
static esp_wps_config_t config;
void wpsInitConfig(){
config.crypto_funcs = &g_wifi_default_wps_crypto_funcs;
config.wps_type = ESP_WPS_MODE;
strcpy(config.factory_info.manufacturer, ESP_MANUFACTURER);
strcpy(config.factory_info.model_number, ESP_MODEL_NUMBER);

View File

@ -36,8 +36,10 @@ void setup()
void loop()
{
const uint16_t port = 80;
const char * host = "192.168.1.1"; // ip or dns
// const uint16_t port = 80;
// const char * host = "192.168.1.1"; // ip or dns
const uint16_t port = 1337;
const char * host = "192.168.1.10"; // ip or dns
Serial.print("Connecting to ");
Serial.println(host);
@ -53,11 +55,29 @@ void loop()
}
// This will send a request to the server
client.print("Send this data to the server");
//uncomment this line to send an arbitrary string to the server
//client.print("Send this data to the server");
//uncomment this line to send a basic document request to the server
client.print("GET /index.html HTTP/1.1\n\n");
int maxloops = 0;
//wait for the server's reply to become available
while (!client.available() && maxloops < 1000)
{
maxloops++;
delay(1); //delay 1 msec
}
if (client.available() > 0)
{
//read back one line from the server
String line = client.readStringUntil('\r');
client.println(line);
Serial.println(line);
}
else
{
Serial.println("client.available() timed out ");
}
Serial.println("Closing connection.");
client.stop();
@ -65,4 +85,3 @@ void loop()
Serial.println("Waiting 5 seconds before restarting...");
delay(5000);
}

View File

@ -16,8 +16,7 @@ void setup() {
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); //set config settings to default
esp_wifi_sta_wpa2_ent_enable(&config); //set config settings to enable function
esp_wifi_sta_wpa2_ent_enable();
WiFi.begin(ssid); //connect to wifi
while (WiFi.status() != WL_CONNECTED) {
delay(500);

View File

@ -19,14 +19,86 @@
*/
#include "ETH.h"
#include "eth_phy/phy.h"
#include "eth_phy/phy_tlk110.h"
#include "eth_phy/phy_lan8720.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR
#include "esp_event.h"
#include "esp_eth.h"
#include "esp_eth_phy.h"
#include "esp_eth_mac.h"
#include "esp_eth_com.h"
#else
#include "eth_phy/phy.h"
#include "eth_phy/phy_tlk110.h"
#include "eth_phy/phy_lan8720.h"
#endif
#include "lwip/err.h"
#include "lwip/dns.h"
extern void tcpipInit();
#ifdef ESP_IDF_VERSION_MAJOR
/**
* @brief Callback function invoked when lowlevel initialization is finished
*
* @param[in] eth_handle: handle of Ethernet driver
*
* @return
* - ESP_OK: process extra lowlevel initialization successfully
* - ESP_FAIL: error occurred when processing extra lowlevel initialization
*/
//static esp_err_t on_lowlevel_init_done(esp_eth_handle_t eth_handle){
//#define PIN_PHY_POWER 2
// pinMode(PIN_PHY_POWER, OUTPUT);
// digitalWrite(PIN_PHY_POWER, HIGH);
// delay(100);
// return ESP_OK;
//}
/**
* @brief Callback function invoked when lowlevel deinitialization is finished
*
* @param[in] eth_handle: handle of Ethernet driver
*
* @return
* - ESP_OK: process extra lowlevel deinitialization successfully
* - ESP_FAIL: error occurred when processing extra lowlevel deinitialization
*/
//static esp_err_t on_lowlevel_deinit_done(esp_eth_handle_t eth_handle){
// return ESP_OK;
//}
// Event handler for Ethernet
void ETHClass::eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
system_event_t event;
switch (event_id) {
case ETHERNET_EVENT_CONNECTED:
event.event_id = SYSTEM_EVENT_ETH_CONNECTED;
((ETHClass*)(arg))->eth_link = ETH_LINK_UP;
break;
case ETHERNET_EVENT_DISCONNECTED:
event.event_id = SYSTEM_EVENT_ETH_DISCONNECTED;
((ETHClass*)(arg))->eth_link = ETH_LINK_DOWN;
break;
case ETHERNET_EVENT_START:
event.event_id = SYSTEM_EVENT_ETH_START;
((ETHClass*)(arg))->started = true;
break;
case ETHERNET_EVENT_STOP:
event.event_id = SYSTEM_EVENT_ETH_STOP;
((ETHClass*)(arg))->started = false;
break;
default:
break;
}
WiFi._eventCallback(arg, &event);
}
#else
static int _eth_phy_mdc_pin = -1;
static int _eth_phy_mdio_pin = -1;
static int _eth_phy_power_pin = -1;
@ -48,14 +120,100 @@ static void _eth_phy_power_enable(bool enable)
digitalWrite(_eth_phy_power_pin, enable);
delay(1);
}
#endif
ETHClass::ETHClass():initialized(false),started(false),staticIP(false)
ETHClass::ETHClass()
:initialized(false)
,staticIP(false)
#if ESP_IDF_VERSION_MAJOR > 3
,eth_handle(NULL)
#endif
,started(false)
#if ESP_IDF_VERSION_MAJOR > 3
,eth_link(ETH_LINK_DOWN)
#endif
{
}
ETHClass::~ETHClass()
{}
#ifdef ESP_IDF_VERSION_MAJOR
bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type){
tcpipInit();
tcpip_adapter_set_default_eth_handlers();
esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler, this);
//ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
mac_config.smi_mdc_gpio_num = mdc;
mac_config.smi_mdio_gpio_num = mdio;
//mac_config.sw_reset_timeout_ms = 1000;
esp_eth_mac_t *eth_mac = NULL;
#if CONFIG_ETH_SPI_ETHERNET_DM9051
if(type == ETH_PHY_DM9051){
return false;//todo
} else {
#endif
eth_mac = esp_eth_mac_new_esp32(&mac_config);
#if CONFIG_ETH_SPI_ETHERNET_DM9051
}
#endif
if(eth_mac == NULL){
log_e("esp_eth_mac_new_esp32 failed");
return false;
}
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
phy_config.phy_addr = phy_addr;
phy_config.reset_gpio_num = power;
esp_eth_phy_t *eth_phy = NULL;
switch(type){
case ETH_PHY_LAN8720:
eth_phy = esp_eth_phy_new_lan8720(&phy_config);
break;
case ETH_PHY_TLK110:
eth_phy = esp_eth_phy_new_ip101(&phy_config);
break;
case ETH_PHY_RTL8201:
eth_phy = esp_eth_phy_new_rtl8201(&phy_config);
break;
case ETH_PHY_DP83848:
eth_phy = esp_eth_phy_new_dp83848(&phy_config);
break;
#if CONFIG_ETH_SPI_ETHERNET_DM9051
case ETH_PHY_DM9051:
eth_phy = esp_eth_phy_new_dm9051(&phy_config);
break;
#endif
default:
break;
}
if(eth_phy == NULL){
log_e("esp_eth_phy_new failed");
return false;
}
eth_handle = NULL;
esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(eth_mac, eth_phy);
//eth_config.on_lowlevel_init_done = on_lowlevel_init_done;
//eth_config.on_lowlevel_deinit_done = on_lowlevel_deinit_done;
if(esp_eth_driver_install(&eth_config, &eth_handle) != ESP_OK || eth_handle == NULL){
log_e("esp_eth_driver_install failed");
return false;
}
if(esp_eth_start(eth_handle) != ESP_OK){
log_e("esp_eth_start failed");
return false;
}
return true;
}
#else
bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type, eth_clock_mode_t clock_mode)
{
esp_err_t err;
@ -108,6 +266,7 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ
}
return false;
}
#endif
bool ETHClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
{
@ -193,8 +352,8 @@ IPAddress ETHClass::gatewayIP()
IPAddress ETHClass::dnsIP(uint8_t dns_no)
{
ip_addr_t dns_ip = dns_getserver(dns_no);
return IPAddress(dns_ip.u_addr.ip4.addr);
const ip_addr_t * dns_ip = dns_getserver(dns_no);
return IPAddress(dns_ip->u_addr.ip4.addr);
}
IPAddress ETHClass::broadcastIP()
@ -240,17 +399,31 @@ bool ETHClass::setHostname(const char * hostname)
bool ETHClass::fullDuplex()
{
#ifdef ESP_IDF_VERSION_MAJOR
return true;//todo: do not see an API for this
#else
return eth_config.phy_get_duplex_mode();
#endif
}
bool ETHClass::linkUp()
{
#ifdef ESP_IDF_VERSION_MAJOR
return eth_link == ETH_LINK_UP;
#else
return eth_config.phy_check_link();
#endif
}
uint8_t ETHClass::linkSpeed()
{
#ifdef ESP_IDF_VERSION_MAJOR
eth_speed_t link_speed;
esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &link_speed);
return (link_speed == ETH_SPEED_10M)?10:100;
#else
return eth_config.phy_get_speed_mode()?100:10;
#endif
}
bool ETHClass::enableIpV6()
@ -267,20 +440,24 @@ IPv6Address ETHClass::localIPv6()
return IPv6Address(addr.addr);
}
uint8_t * macAddress(uint8_t* mac)
uint8_t * ETHClass::macAddress(uint8_t* mac)
{
if(!mac){
return NULL;
}
#ifdef ESP_IDF_VERSION_MAJOR
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac);
#else
esp_eth_get_mac(mac);
#endif
return mac;
}
String ETHClass::macAddress(void)
{
uint8_t mac[6];
uint8_t mac[6] = {0,0,0,0,0,0};
char macStr[18] = { 0 };
esp_eth_get_mac(mac);
macAddress(mac);
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return String(macStr);
}

View File

@ -22,6 +22,7 @@
#define _ETH_H_
#include "WiFi.h"
#include "esp_system.h"
#include "esp_eth.h"
#ifndef ETH_PHY_ADDR
@ -44,24 +45,39 @@
#define ETH_PHY_MDIO 18
#endif
#if ESP_IDF_VERSION_MAJOR < 4
#ifndef ETH_CLK_MODE
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#endif
#endif
typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_MAX } eth_phy_type_t;
typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, ETH_PHY_DP83848, ETH_PHY_DM9051, ETH_PHY_MAX } eth_phy_type_t;
class ETHClass {
private:
bool initialized;
bool started;
bool staticIP;
#if ESP_IDF_VERSION_MAJOR > 3
esp_eth_handle_t eth_handle;
protected:
bool started;
eth_link_t eth_link;
static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
#else
bool started;
eth_config_t eth_config;
#endif
public:
ETHClass();
~ETHClass();
#if ESP_IDF_VERSION_MAJOR > 3
bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE);
#else
bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE);
#endif
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
const char * getHostname();

View File

@ -46,7 +46,11 @@ private:
return 0;
}
int count;
#ifdef ESP_IDF_VERSION_MAJOR
int res = lwip_ioctl(_fd, FIONREAD, &count);
#else
int res = lwip_ioctl_r(_fd, FIONREAD, &count);
#endif
if(res < 0) {
_failed = true;
return 0;
@ -227,7 +231,11 @@ int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout)
tv.tv_sec = 0;
tv.tv_usec = timeout * 1000;
#ifdef ESP_IDF_VERSION_MAJOR
int res = lwip_connect(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
#else
int res = lwip_connect_r(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
#endif
if (res < 0 && errno != EINPROGRESS) {
log_e("connect on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno));
close(sockfd);
@ -495,23 +503,28 @@ uint8_t WiFiClient::connected()
int res = recv(fd(), &dummy, 0, MSG_DONTWAIT);
// avoid unused var warning by gcc
(void)res;
switch (errno) {
case EWOULDBLOCK:
case ENOENT: //caused by vfs
_connected = true;
break;
case ENOTCONN:
case EPIPE:
case ECONNRESET:
case ECONNREFUSED:
case ECONNABORTED:
_connected = false;
log_d("Disconnected: RES: %d, ERR: %d", res, errno);
break;
default:
log_i("Unexpected: RES: %d, ERR: %d", res, errno);
_connected = true;
break;
// recv only sets errno if res is <= 0
if (res <= 0){
switch (errno) {
case EWOULDBLOCK:
case ENOENT: //caused by vfs
_connected = true;
break;
case ENOTCONN:
case EPIPE:
case ECONNRESET:
case ECONNREFUSED:
case ECONNABORTED:
_connected = false;
log_d("Disconnected: RES: %d, ERR: %d", res, errno);
break;
default:
log_i("Unexpected: RES: %d, ERR: %d", res, errno);
_connected = true;
break;
}
} else {
_connected = true;
}
}
return _connected;

View File

@ -47,7 +47,6 @@ extern "C" {
#include "esp32-hal-log.h"
#include <vector>
#include "sdkconfig.h"
static xQueueHandle _network_event_queue;
@ -55,10 +54,10 @@ static TaskHandle_t _network_event_task_handle = NULL;
static EventGroupHandle_t _network_event_group = NULL;
static void _network_event_task(void * arg){
system_event_t *event = NULL;
system_event_t event;
for (;;) {
if(xQueueReceive(_network_event_queue, &event, portMAX_DELAY) == pdTRUE){
WiFiGenericClass::_eventCallback(arg, event);
WiFiGenericClass::_eventCallback(arg, &event);
}
}
vTaskDelete(NULL);
@ -66,7 +65,7 @@ static void _network_event_task(void * arg){
}
static esp_err_t _network_event_cb(void *arg, system_event_t *event){
if (xQueueSend(_network_event_queue, &event, portMAX_DELAY) != pdPASS) {
if (xQueueSend(_network_event_queue, event, portMAX_DELAY) != pdPASS) {
log_w("Network Event Queue Send Failed!");
return ESP_FAIL;
}
@ -83,7 +82,7 @@ static bool _start_network_event_task(){
xEventGroupSetBits(_network_event_group, WIFI_DNS_IDLE_BIT);
}
if(!_network_event_queue){
_network_event_queue = xQueueCreate(32, sizeof(system_event_t *));
_network_event_queue = xQueueCreate(32, sizeof(system_event_t));
if(!_network_event_queue){
log_e("Network Event Queue Create Failed!");
return false;
@ -103,6 +102,13 @@ void tcpipInit(){
static bool initialized = false;
if(!initialized && _start_network_event_task()){
initialized = true;
#ifdef ESP_IDF_VERSION_MAJOR
uint8_t mac[8];
if(esp_efuse_mac_get_default(mac) == ESP_OK){
esp_base_mac_addr_set(mac);
}
esp_event_loop_create_default();
#endif
tcpip_adapter_init();
}
}
@ -133,24 +139,19 @@ static bool wifiLowLevelDeinit(){
static bool _esp_wifi_started = false;
static bool espWiFiStart(bool persistent){
static bool espWiFiStart(){
if(_esp_wifi_started){
return true;
}
if(!wifiLowLevelInit(persistent)){
return false;
}
esp_err_t err = esp_wifi_start();
if (err != ESP_OK) {
log_e("esp_wifi_start %d", err);
wifiLowLevelDeinit();
return false;
}
_esp_wifi_started = true;
system_event_t event;
event.event_id = SYSTEM_EVENT_WIFI_READY;
WiFiGenericClass::_eventCallback(nullptr, &event);
return true;
}
@ -190,6 +191,7 @@ wifi_event_id_t WiFiEventCbList::current_id = 1;
static std::vector<WiFiEventCbList_t> cbEventList;
bool WiFiGenericClass::_persistent = true;
bool WiFiGenericClass::_long_range = false;
wifi_mode_t WiFiGenericClass::_forceSleepLastMode = WIFI_MODE_NULL;
WiFiGenericClass::WiFiGenericClass()
@ -325,10 +327,10 @@ void WiFiGenericClass::removeEvent(wifi_event_id_t id)
* @param arg
*/
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
const char * system_event_names[] = { "WIFI_READY", "SCAN_DONE", "STA_START", "STA_STOP", "STA_CONNECTED", "STA_DISCONNECTED", "STA_AUTHMODE_CHANGE", "STA_GOT_IP", "STA_LOST_IP", "STA_WPS_ER_SUCCESS", "STA_WPS_ER_FAILED", "STA_WPS_ER_TIMEOUT", "STA_WPS_ER_PIN", "AP_START", "AP_STOP", "AP_STACONNECTED", "AP_STADISCONNECTED", "AP_STAIPASSIGNED", "AP_PROBEREQRECVED", "GOT_IP6", "ETH_START", "ETH_STOP", "ETH_CONNECTED", "ETH_DISCONNECTED", "ETH_GOT_IP", "MAX"};
const char * system_event_names[] = { "WIFI_READY", "SCAN_DONE", "STA_START", "STA_STOP", "STA_CONNECTED", "STA_DISCONNECTED", "STA_AUTHMODE_CHANGE", "STA_GOT_IP", "STA_LOST_IP", "STA_WPS_ER_SUCCESS", "STA_WPS_ER_FAILED", "STA_WPS_ER_TIMEOUT", "STA_WPS_ER_PIN", "STA_WPS_ER_PBC_OVERLAP", "AP_START", "AP_STOP", "AP_STACONNECTED", "AP_STADISCONNECTED", "AP_STAIPASSIGNED", "AP_PROBEREQRECVED", "GOT_IP6", "ETH_START", "ETH_STOP", "ETH_CONNECTED", "ETH_DISCONNECTED", "ETH_GOT_IP", "MAX"};
#endif
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN
const char * system_event_reasons[] = { "UNSPECIFIED", "AUTH_EXPIRE", "AUTH_LEAVE", "ASSOC_EXPIRE", "ASSOC_TOOMANY", "NOT_AUTHED", "NOT_ASSOCED", "ASSOC_LEAVE", "ASSOC_NOT_AUTHED", "DISASSOC_PWRCAP_BAD", "DISASSOC_SUPCHAN_BAD", "UNSPECIFIED", "IE_INVALID", "MIC_FAILURE", "4WAY_HANDSHAKE_TIMEOUT", "GROUP_KEY_UPDATE_TIMEOUT", "IE_IN_4WAY_DIFFERS", "GROUP_CIPHER_INVALID", "PAIRWISE_CIPHER_INVALID", "AKMP_INVALID", "UNSUPP_RSN_IE_VERSION", "INVALID_RSN_IE_CAP", "802_1X_AUTH_FAILED", "CIPHER_SUITE_REJECTED", "BEACON_TIMEOUT", "NO_AP_FOUND", "AUTH_FAIL", "ASSOC_FAIL", "HANDSHAKE_TIMEOUT" };
const char * system_event_reasons[] = { "UNSPECIFIED", "AUTH_EXPIRE", "AUTH_LEAVE", "ASSOC_EXPIRE", "ASSOC_TOOMANY", "NOT_AUTHED", "NOT_ASSOCED", "ASSOC_LEAVE", "ASSOC_NOT_AUTHED", "DISASSOC_PWRCAP_BAD", "DISASSOC_SUPCHAN_BAD", "UNSPECIFIED", "IE_INVALID", "MIC_FAILURE", "4WAY_HANDSHAKE_TIMEOUT", "GROUP_KEY_UPDATE_TIMEOUT", "IE_IN_4WAY_DIFFERS", "GROUP_CIPHER_INVALID", "PAIRWISE_CIPHER_INVALID", "AKMP_INVALID", "UNSUPP_RSN_IE_VERSION", "INVALID_RSN_IE_CAP", "802_1X_AUTH_FAILED", "CIPHER_SUITE_REJECTED", "BEACON_TIMEOUT", "NO_AP_FOUND", "AUTH_FAIL", "ASSOC_FAIL", "HANDSHAKE_TIMEOUT", "CONNECTION_FAIL" };
#define reason2str(r) ((r>176)?system_event_reasons[r-176]:system_event_reasons[r-1])
#endif
esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event)
@ -471,6 +473,16 @@ void WiFiGenericClass::persistent(bool persistent)
}
/**
* enable WiFi long range mode
* @param enable
*/
void WiFiGenericClass::enableLongRange(bool enable)
{
_long_range = enable;
}
/**
* set new mode
* @param m WiFiMode_t
@ -482,7 +494,7 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
return true;
}
if(!cm && m){
if(!espWiFiStart(_persistent)){
if(!wifiLowLevelInit(_persistent)){
return false;
}
} else if(cm && !m){
@ -495,6 +507,25 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
log_e("Could not set mode! %d", err);
return false;
}
if(_long_range){
if(m & WIFI_MODE_STA){
err = esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_LR);
if(err != ESP_OK){
log_e("Could not enable long range on STA! %d", err);
return false;
}
}
if(m & WIFI_MODE_AP){
err = esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_LR);
if(err != ESP_OK){
log_e("Could not enable long range on AP! %d", err);
return false;
}
}
}
if(!espWiFiStart()){
return false;
}
return true;
}
@ -504,7 +535,7 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
*/
wifi_mode_t WiFiGenericClass::getMode()
{
if(!_esp_wifi_started){
if(!lowLevelInitDone){
return WIFI_MODE_NULL;
}
wifi_mode_t mode;

View File

@ -83,6 +83,7 @@ class WiFiGenericClass
int32_t channel(void);
void persistent(bool persistent);
void enableLongRange(bool enable);
static bool mode(wifi_mode_t);
static wifi_mode_t getMode();
@ -100,6 +101,7 @@ class WiFiGenericClass
protected:
static bool _persistent;
static bool _long_range;
static wifi_mode_t _forceSleepLastMode;
static int setStatusBits(int bits);

View File

@ -488,8 +488,8 @@ IPAddress WiFiSTAClass::dnsIP(uint8_t dns_no)
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
return IPAddress();
}
ip_addr_t dns_ip = dns_getserver(dns_no);
return IPAddress(dns_ip.u_addr.ip4.addr);
const ip_addr_t * dns_ip = dns_getserver(dns_no);
return IPAddress(dns_ip->u_addr.ip4.addr);
}
/**
@ -687,7 +687,13 @@ bool WiFiSTAClass::beginSmartConfig() {
esp_wifi_disconnect();
esp_err_t err;
#ifdef ESP_IDF_VERSION_MAJOR
esp_event_handler_register(SC_EVENT, ESP_EVENT_ANY_ID, _smartConfigCallback, this);
smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT();
err = esp_smartconfig_start(&conf);
#else
err = esp_smartconfig_start(reinterpret_cast<sc_callback_t>(&WiFiSTAClass::_smartConfigCallback), 1);
#endif
if (err == ESP_OK) {
_smartConfigStarted = true;
_smartConfigDone = false;
@ -717,6 +723,45 @@ bool WiFiSTAClass::smartConfigDone() {
return _smartConfigDone;
}
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
const char * sc_type_strings[] = {
"ESPTOUCH",
"AIRKISS",
"ESPTOUCH_AIRKISS"
};
#endif
#ifdef ESP_IDF_VERSION_MAJOR //todo
void WiFiSTAClass::_smartConfigCallback(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data){
smartconfig_event_t event = (smartconfig_event_t)event_id;
switch(event){
case SC_EVENT_SCAN_DONE:
log_d("smartconfig has finished to scan for APs");
break;
case SC_EVENT_FOUND_CHANNEL:
log_d("smartconfig has found the channel of the target AP");
break;
case SC_EVENT_GOT_SSID_PSWD:
{
log_d("smartconfig got the SSID and password");
smartconfig_event_got_ssid_pswd_t * data = (smartconfig_event_got_ssid_pswd_t*)event_data;
log_d("Type: %s", sc_type_strings[data->type]);
log_d("SSID: %s", (const char *)data->ssid);
log_d("Password: %s", (const char *)data->password);
log_d("Sender IP: " IPSTR, data->cellphone_ip[3], data->cellphone_ip[2], data->cellphone_ip[1], data->cellphone_ip[0]);
WiFi.begin((const char *)data->ssid, (const char *)data->password);
}
break;
case SC_EVENT_SEND_ACK_DONE:
log_d("smartconfig has sent ACK to the sender");
WiFi.stopSmartConfig();
break;
default: break;
}
}
#else
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
const char * sc_status_strings[] = {
"WAIT",
@ -725,12 +770,6 @@ const char * sc_status_strings[] = {
"LINK",
"LINK_OVER"
};
const char * sc_type_strings[] = {
"ESPTOUCH",
"AIRKISS",
"ESPTOUCH_AIRKISS"
};
#endif
void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
@ -758,3 +797,4 @@ void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
WiFi.stopSmartConfig();
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More