v2.0.0 Add support for ESP32S2 and update ESP-IDF to 4.4 (#4996)

This is very much still work in progress and much more will change before the final 2.0.0

Some APIs have changed. New libraries have been added. LittleFS included.

Co-authored-by: Seon Rozenblum <seonr@3sprockets.com>
Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
Co-authored-by: geeksville <kevinh@geeksville.com>
Co-authored-by: Mike Dunston <m_dunston@comcast.net>
Co-authored-by: Unexpected Maker <seon@unexpectedmaker.com>
Co-authored-by: Seon Rozenblum <seonr@3sprockets.com>
Co-authored-by: microDev <70126934+microDev1@users.noreply.github.com>
Co-authored-by: tobozo <tobozo@users.noreply.github.com>
Co-authored-by: bobobo1618 <bobobo1618@users.noreply.github.com>
Co-authored-by: lorol <lorolouis@gmail.com>
Co-authored-by: geeksville <kevinh@geeksville.com>
Co-authored-by: Limor "Ladyada" Fried <limor@ladyada.net>
Co-authored-by: Sweety <switi.mhaiske@espressif.com>
Co-authored-by: Loick MAHIEUX <loick111@gmail.com>
Co-authored-by: Larry Bernstone <lbernstone@gmail.com>
Co-authored-by: Valerii Koval <valeros@users.noreply.github.com>
Co-authored-by: 快乐的我531 <2302004040@qq.com>
Co-authored-by: chegewara <imperiaonline4@gmail.com>
Co-authored-by: Clemens Kirchgatterer <clemens@1541.org>
Co-authored-by: Aron Rubin <aronrubin@gmail.com>
Co-authored-by: Pete Lewis <601236+lewispg228@users.noreply.github.com>
This commit is contained in:
Me No Dev
2021-04-05 14:23:58 +03:00
committed by GitHub
parent 46d5afb17f
commit 5502879a5b
5209 changed files with 826360 additions and 322816 deletions

View File

@ -7,7 +7,7 @@
#include <functional>
extern "C" {
#include "lwip/ip_addr.h"
#include <tcpip_adapter.h>
#include "esp_netif.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
}

View File

@ -10,7 +10,7 @@
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLE2902.h"

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLE2902_H_
#define COMPONENTS_CPP_UTILS_BLE2902_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLEDescriptor.h"
@ -30,5 +30,5 @@ public:
}; // BLE2902
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLE2902_H_ */

View File

@ -10,7 +10,7 @@
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLE2904.h"

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLE2904_H_
#define COMPONENTS_CPP_UTILS_BLE2904_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLEDescriptor.h"
@ -70,5 +70,5 @@ private:
BLE2904_Data m_data;
}; // BLE2904
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLE2904_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLEAddress.h"
#include <string>

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLEADDRESS_H_
#define COMPONENTS_CPP_UTILS_BLEADDRESS_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gap_ble_api.h> // ESP32 BLE
#include <string>
@ -36,5 +36,5 @@ private:
esp_bd_addr_t m_address;
};
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEADDRESS_H_ */

View File

@ -12,7 +12,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <sstream>
#include "BLEAdvertisedDevice.h"
#include "BLEUtils.h"
@ -555,7 +555,7 @@ std::string BLEAdvertisedDevice::toString() {
}
}
if (haveTXPower()) {
char val[4];
char val[6];
snprintf(val, sizeof(val), "%d", getTXPower());
res += ", txPower: ";
res += val;
@ -579,5 +579,5 @@ size_t BLEAdvertisedDevice::getPayloadLength() {
return m_payloadLength;
}
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLEADVERTISEDDEVICE_H_
#define COMPONENTS_CPP_UTILS_BLEADVERTISEDDEVICE_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gattc_api.h>
#include <map>
@ -124,5 +124,5 @@ public:
virtual void onResult(BLEAdvertisedDevice advertisedDevice) = 0;
};
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEADVERTISEDDEVICE_H_ */

View File

@ -17,7 +17,7 @@
*
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLEAdvertising.h"
#include <esp_err.h>
#include "BLEUtils.h"
@ -529,4 +529,4 @@ void BLEAdvertising::handleGAPEvent(
}
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -8,11 +8,11 @@
#ifndef COMPONENTS_CPP_UTILS_BLEADVERTISING_H_
#define COMPONENTS_CPP_UTILS_BLEADVERTISING_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gap_ble_api.h>
#include "BLEUUID.h"
#include <vector>
#include "FreeRTOS.h"
#include "RTOS.h"
/**
* @brief Advertisement data set by the programmer to be published by the %BLE server.
@ -78,5 +78,5 @@ private:
bool m_scanResp = true;
};
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEADVERTISING_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string.h>
#include "BLEBeacon.h"
#include "esp32-hal-log.h"

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <sstream>
#include <string.h>
#include <iomanip>
@ -800,4 +800,4 @@ void BLECharacteristicCallbacks::onStatus(BLECharacteristic* pCharacteristic, St
} // onStatus
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLECHARACTERISTIC_H_
#define COMPONENTS_CPP_UTILS_BLECHARACTERISTIC_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string>
#include <map>
#include "BLEUUID.h"
@ -16,7 +16,7 @@
#include <esp_gap_ble_api.h>
#include "BLEDescriptor.h"
#include "BLEValue.h"
#include "FreeRTOS.h"
#include "RTOS.h"
class BLEService;
class BLEDescriptor;
@ -150,5 +150,5 @@ public:
virtual void onNotify(BLECharacteristic* pCharacteristic);
virtual void onStatus(BLECharacteristic* pCharacteristic, Status s, uint32_t code);
};
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLECHARACTERISTIC_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <sstream>
#include <iomanip>
#include "BLEService.h"
@ -131,4 +131,4 @@ std::string BLECharacteristicMap::toString() {
} // toString
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_bt.h>
#include <esp_bt_main.h>
#include <esp_gap_ble_api.h>
@ -560,4 +560,4 @@ std::string BLEClient::toString() {
} // toString
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED

View File

@ -9,7 +9,7 @@
#define MAIN_BLEDEVICE_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gattc_api.h>
#include <string.h>
@ -99,5 +99,5 @@ public:
virtual void onDisconnect(BLEClient *pClient) = 0;
};
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED
#endif /* MAIN_BLEDEVICE_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <sstream>
#include <string.h>
#include <iomanip>
@ -284,4 +284,4 @@ void BLEDescriptorCallbacks::onWrite(BLEDescriptor* pDescriptor) {
} // onWrite
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -8,12 +8,12 @@
#ifndef COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_
#define COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string>
#include "BLEUUID.h"
#include "BLECharacteristic.h"
#include <esp_gatts_api.h>
#include "FreeRTOS.h"
#include "RTOS.h"
class BLEService;
class BLECharacteristic;
@ -73,5 +73,5 @@ public:
virtual void onRead(BLEDescriptor* pDescriptor);
virtual void onWrite(BLEDescriptor* pDescriptor);
};
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <sstream>
#include <iomanip>
#include "BLECharacteristic.h"
@ -145,4 +145,4 @@ BLEDescriptor* BLEDescriptorMap::getNext() {
m_iterator++;
return pRet;
} // getNext
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <freertos/FreeRTOS.h>
#include <freertos/event_groups.h>
#include <freertos/task.h>
@ -499,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));
}
@ -513,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));
}
@ -661,4 +669,4 @@ void BLEDevice::setCustomGattsHandler(gatts_event_handler handler) {
m_customGattsHandler = handler;
}
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED

View File

@ -8,7 +8,7 @@
#ifndef MAIN_BLEDevice_H_
#define MAIN_BLEDevice_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gap_ble_api.h> // ESP32 BLE
#include <esp_gattc_api.h> // ESP32 BLE
#include <map> // Part of C++ STL
@ -96,5 +96,5 @@ public:
}; // class BLE
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED
#endif /* MAIN_BLEDevice_H_ */

View File

@ -10,7 +10,7 @@
*
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string.h>
#include <stdio.h>
#include "esp32-hal-log.h"

View File

@ -5,7 +5,7 @@
* Author: pcbreflux
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string.h>
#include "esp32-hal-log.h"
#include "BLEEddystoneURL.h"

View File

@ -5,7 +5,7 @@
* Author: chegewara
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLEHIDDevice.h"
#include "BLE2904.h"
@ -240,5 +240,5 @@ BLEService* BLEHIDDevice::batteryService() {
return m_batteryService;
}
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED

View File

@ -9,7 +9,7 @@
#define _BLEHIDDEVICE_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLECharacteristic.h"
#include "BLEService.h"
@ -71,5 +71,5 @@ private:
BLECharacteristic* m_protocolModeCharacteristic; //0x2a4e
BLECharacteristic* m_batteryLevelCharacteristic; //0x2a19
};
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED
#endif /* _BLEHIDDEVICE_H_ */

View File

@ -8,7 +8,7 @@
#include "BLERemoteCharacteristic.h"
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gattc_api.h>
#include <esp_err.h>
@ -618,4 +618,4 @@ void BLERemoteCharacteristic::setAuth(esp_gatt_auth_req_t auth) {
m_auth = auth;
}
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLEREMOTECHARACTERISTIC_H_
#define COMPONENTS_CPP_UTILS_BLEREMOTECHARACTERISTIC_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string>
#include <functional>
@ -18,7 +18,7 @@
#include "BLERemoteService.h"
#include "BLERemoteDescriptor.h"
#include "BLEUUID.h"
#include "FreeRTOS.h"
#include "RTOS.h"
class BLERemoteService;
class BLERemoteDescriptor;
@ -83,5 +83,5 @@ private:
// We maintain a map of descriptors owned by this characteristic keyed by a string representation of the UUID.
std::map<std::string, BLERemoteDescriptor*> m_descriptorMap;
}; // BLERemoteCharacteristic
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEREMOTECHARACTERISTIC_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <sstream>
#include "BLERemoteDescriptor.h"
#include "GeneralUtils.h"
@ -201,4 +201,4 @@ void BLERemoteDescriptor::setAuth(esp_gatt_auth_req_t auth) {
m_auth = auth;
}
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -8,14 +8,14 @@
#ifndef COMPONENTS_CPP_UTILS_BLEREMOTEDESCRIPTOR_H_
#define COMPONENTS_CPP_UTILS_BLEREMOTEDESCRIPTOR_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string>
#include <esp_gattc_api.h>
#include "BLERemoteCharacteristic.h"
#include "BLEUUID.h"
#include "FreeRTOS.h"
#include "RTOS.h"
class BLERemoteCharacteristic;
/**
@ -54,5 +54,5 @@ private:
};
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEREMOTEDESCRIPTOR_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <sstream>
#include "BLERemoteService.h"
@ -243,7 +243,7 @@ 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) {
void BLERemoteService::getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>** pCharacteristicMap) {
log_v(">> getCharacteristics() for service: %s", getUUID().toString().c_str());
(void)pCharacteristicMap;
// If is possible that we have not read the characteristics associated with the service so do that
@ -253,7 +253,7 @@ void BLERemoteService::getCharacteristics(std::map<uint16_t, BLERemoteCharacteri
retrieveCharacteristics();
}
log_v("<< getCharacteristics() for service: %s", getUUID().toString().c_str());
*pCharacteristicMap = m_characteristicMapByHandle;
*pCharacteristicMap = &m_characteristicMapByHandle;
} // Get the characteristics map.
/**
@ -360,4 +360,4 @@ std::string BLERemoteService::toString() {
} // toString
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -8,14 +8,14 @@
#ifndef COMPONENTS_CPP_UTILS_BLEREMOTESERVICE_H_
#define COMPONENTS_CPP_UTILS_BLEREMOTESERVICE_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <map>
#include "BLEClient.h"
#include "BLERemoteCharacteristic.h"
#include "BLEUUID.h"
#include "FreeRTOS.h"
#include "RTOS.h"
class BLEClient;
class BLERemoteCharacteristic;
@ -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.
@ -81,5 +81,5 @@ private:
uint16_t m_endHandle; // The ending handle of this service.
}; // BLERemoteService
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEREMOTESERVICE_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_err.h>
@ -330,4 +330,4 @@ void BLEScan::clearResults() {
m_scanResults.m_vectorAdvertisedDevices.clear();
}
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -8,14 +8,14 @@
#ifndef COMPONENTS_CPP_UTILS_BLESCAN_H_
#define COMPONENTS_CPP_UTILS_BLESCAN_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gap_ble_api.h>
// #include <vector>
#include <string>
#include "BLEAdvertisedDevice.h"
#include "BLEClient.h"
#include "FreeRTOS.h"
#include "RTOS.h"
class BLEAdvertisedDevice;
class BLEAdvertisedDeviceCallbacks;
@ -81,5 +81,5 @@ private:
void (*m_scanCompleteCB)(BLEScanResults scanResults);
}; // BLEScan
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLESCAN_H_ */

View File

@ -7,7 +7,7 @@
#include "BLESecurity.h"
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
BLESecurity::BLESecurity() {
}
@ -112,4 +112,4 @@ char* BLESecurity::esp_key_type_to_str(esp_ble_key_type_t key_type) {
}
return key_str;
} // esp_key_type_to_str
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLESECURITY_H_
#define COMPONENTS_CPP_UTILS_BLESECURITY_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gap_ble_api.h>
@ -69,5 +69,5 @@ public:
virtual bool onConfirmPIN(uint32_t pin) = 0;
}; // BLESecurityCallbacks
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED
#endif // COMPONENTS_CPP_UTILS_BLESECURITY_H_

View File

@ -6,7 +6,7 @@
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_bt.h>
#include <esp_bt_main.h>
#include "GeneralUtils.h"
@ -423,4 +423,4 @@ void BLEServer::disconnect(uint16_t connId) {
esp_ble_gatts_close(m_gatts_if, connId);
}
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLESERVER_H_
#define COMPONENTS_CPP_UTILS_BLESERVER_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gatts_api.h>
#include <string>
@ -20,7 +20,7 @@
#include "BLECharacteristic.h"
#include "BLEService.h"
#include "BLESecurity.h"
#include "FreeRTOS.h"
#include "RTOS.h"
#include "BLEAddress.h"
class BLEServerCallbacks;
@ -137,5 +137,5 @@ public:
}; // BLEServerCallbacks
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLESERVER_H_ */

View File

@ -8,7 +8,7 @@
// A service is identified by a UUID. A service is also the container for one or more characteristics.
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_err.h>
#include <esp_gatts_api.h>
@ -410,4 +410,4 @@ BLEServer* BLEService::getServer() {
return m_pServer;
} // getServer
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED

View File

@ -8,14 +8,14 @@
#ifndef COMPONENTS_CPP_UTILS_BLESERVICE_H_
#define COMPONENTS_CPP_UTILS_BLESERVICE_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gatts_api.h>
#include "BLECharacteristic.h"
#include "BLEServer.h"
#include "BLEUUID.h"
#include "FreeRTOS.h"
#include "RTOS.h"
class BLEServer;
@ -93,5 +93,5 @@ private:
}; // BLEService
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED
#endif /* COMPONENTS_CPP_UTILS_BLESERVICE_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <stdio.h>
#include <iomanip>
#include "BLEService.h"
@ -134,4 +134,4 @@ int BLEServiceMap::getRegisteredServiceCount(){
return m_handleMap.size();
}
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string.h>
#include <sstream>
#include <iomanip>
@ -383,4 +383,4 @@ std::string BLEUUID::toString() {
return res;
} // toString
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */

View File

@ -8,9 +8,9 @@
#ifndef COMPONENTS_CPP_UTILS_BLEUUID_H_
#define COMPONENTS_CPP_UTILS_BLEUUID_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include <esp_gatt_defs.h>
#include <string>
#if CONFIG_BLUEDROID_ENABLED
#include <esp_gatt_defs.h>
/**
* @brief A model of a %BLE UUID.
@ -35,5 +35,5 @@ private:
esp_bt_uuid_t m_uuid; // The underlying UUID structure that this class wraps.
bool m_valueSet = false; // Is there a value set for this instance.
}; // BLEUUID
#endif /* CONFIG_BT_ENABLED */
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEUUID_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLEAddress.h"
#include "BLEClient.h"
#include "BLEUtils.h"
@ -2037,4 +2037,4 @@ const char* BLEUtils::searchEventTypeToString(esp_gap_search_evt_t searchEvt) {
}
} // searchEventTypeToString
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLEUTILS_H_
#define COMPONENTS_CPP_UTILS_BLEUTILS_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gattc_api.h> // ESP32 BLE
#include <esp_gatts_api.h> // ESP32 BLE
#include <esp_gap_ble_api.h> // ESP32 BLE
@ -59,5 +59,5 @@ public:
static const char* searchEventTypeToString(esp_gap_search_evt_t searchEvt);
};
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED
#endif /* COMPONENTS_CPP_UTILS_BLEUTILS_H_ */

View File

@ -5,7 +5,7 @@
* Author: kolban
*/
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include "BLEValue.h"
#include "esp32-hal-log.h"
@ -127,4 +127,4 @@ void BLEValue::setValue(uint8_t* pData, size_t length) {
} // setValue
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED

View File

@ -8,7 +8,7 @@
#ifndef COMPONENTS_CPP_UTILS_BLEVALUE_H_
#define COMPONENTS_CPP_UTILS_BLEVALUE_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <string>
/**
@ -35,5 +35,5 @@ private:
std::string m_value;
};
#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BLUEDROID_ENABLED
#endif /* COMPONENTS_CPP_UTILS_BLEVALUE_H_ */

View File

@ -10,7 +10,7 @@
#include <string>
#include <sstream>
#include <iomanip>
#include "FreeRTOS.h"
#include "RTOS.h"
#include "sdkconfig.h"
#include "esp32-hal-log.h"
@ -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

@ -12,7 +12,7 @@
#include <string>
#include <sstream>
#include <iomanip>
#include "FreeRTOS.h"
#include "RTOS.h"
#include <esp_err.h>
#include <nvs.h>
#include <esp_wifi.h>

View File

@ -5,6 +5,7 @@
* Author: kolban
*/
#ifdef __cplusplus
#ifndef MAIN_FREERTOS_H_
#define MAIN_FREERTOS_H_
#include <stdint.h>
@ -60,7 +61,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);
@ -71,3 +76,6 @@ private:
};
#endif /* MAIN_FREERTOS_H_ */
#else
#include "freertos/FreeRTOS.h"
#endif

View File

@ -26,4 +26,4 @@ void loop() {
Serial.write(SerialBT.read());
}
delay(20);
}
}

View File

@ -14,7 +14,7 @@ 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";
char *pin = "1234"; //<- standard pin would be provided by default
const char *pin = "1234"; //<- standard pin would be provided by default
bool connected;
void setup() {

View File

@ -241,7 +241,11 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
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);
#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);
@ -520,7 +524,7 @@ static bool _init_bt(const char *deviceName)
}
if(!_spp_task_handle){
xTaskCreatePinnedToCore(_spp_tx_task, "spp_tx", 4096, NULL, 2, &_spp_task_handle, 0);
xTaskCreatePinnedToCore(_spp_tx_task, "spp_tx", 4096, NULL, 10, &_spp_task_handle, 0);
if(!_spp_task_handle){
log_e("Network Event Task Start Failed!");
return false;
@ -782,7 +786,11 @@ bool BluetoothSerial::connect(String remoteName)
_remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0;
log_i("master : remoteName");
// will first resolve name to address
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
#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);
}
@ -822,7 +830,11 @@ bool BluetoothSerial::connect()
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);
}
@ -868,4 +880,9 @@ bool BluetoothSerial::isReady(bool checkMaster, int timeout) {
TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS;
return (xEventGroupWaitBits(_spp_event_group, SPP_RUNNING, pdFALSE, pdTRUE, xTicksToWait) & SPP_RUNNING) != 0;
}
BluetoothSerial::operator bool() const
{
return true;
}
#endif

View File

@ -36,6 +36,9 @@ class BluetoothSerial: public Stream
~BluetoothSerial(void);
bool begin(String localName=String(), bool isMaster=false);
bool begin(unsigned long baud){//compatibility
return begin();
}
int available(void);
int peek(void);
bool hasClient(void);
@ -60,7 +63,8 @@ class BluetoothSerial: public Stream
bool isReady(bool checkMaster=false, int timeout=0);
bool disconnect();
bool unpairDevice(uint8_t remoteAddress[]);
operator bool() const;
private:
String local_name;

View File

@ -53,10 +53,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

@ -1,3 +1,5 @@
//Disable Example for now
#if 0
#include "esp_camera.h"
#include <WiFi.h>
@ -110,3 +112,7 @@ void loop() {
// put your main code here, to run repeatedly:
delay(10000);
}
#else
void setup(){}
void loop(){}
#endif

View File

@ -11,6 +11,7 @@
// 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.
#if 0
#include "esp_http_server.h"
#include "esp_timer.h"
#include "esp_camera.h"
@ -56,11 +57,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));
@ -660,3 +661,4 @@ void startCameraServer(){
httpd_register_uri_handler(stream_httpd, &stream_uri);
}
}
#endif

View File

@ -15,7 +15,7 @@ public:
detachInterrupt(PIN);
}
void IRAM_ATTR isr() {
void ARDUINO_ISR_ATTR isr() {
numberKeyPresses += 1;
pressed = true;
}

View File

@ -9,13 +9,13 @@ struct Button {
Button button1 = {23, 0, false};
Button button2 = {18, 0, false};
void IRAM_ATTR isr(void* arg) {
void ARDUINO_ISR_ATTR isr(void* arg) {
Button* s = static_cast<Button*>(arg);
s->numberKeyPresses += 1;
s->pressed = true;
}
void IRAM_ATTR isr() {
void ARDUINO_ISR_ATTR isr() {
button2.numberKeyPresses += 1;
button2.pressed = true;
}

View File

@ -1,7 +1,6 @@
//Simple sketch to access the internal hall effect detector on the esp32.
//values can be quite low.
//Brian Degger / @sctv
int val = 0;
void setup() {
Serial.begin(9600);

View File

@ -12,7 +12,17 @@
* 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"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/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

@ -18,7 +18,7 @@ portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
volatile uint32_t isrCounter = 0;
volatile uint32_t lastIsrAt = 0;
void IRAM_ATTR onTimer(){
void ARDUINO_ISR_ATTR onTimer(){
// Increment the counter and set the time of ISR
portENTER_CRITICAL_ISR(&timerMux);
isrCounter++;

View File

@ -4,7 +4,7 @@ const int button = 0; //gpio to use to trigger delay
const int wdtTimeout = 3000; //time in ms to trigger the watchdog
hw_timer_t *timer = NULL;
void IRAM_ATTR resetModule() {
void ARDUINO_ISR_ATTR resetModule() {
ets_printf("reboot\n");
esp_restart();
}

View File

@ -10,6 +10,6 @@ void setup()
void loop()
{
Serial.println(touchRead(T0)); // get value using T0
Serial.println(touchRead(T1)); // get value using T0
delay(1000);
}

View File

@ -51,9 +51,9 @@ License (MIT license):
#define STR(tok) tok
#endif
static void _on_sys_event(system_event_t *event){
mdns_handle_system_event(NULL, event);
}
// static void _on_sys_event(arduino_event_t *event){
// mdns_handle_system_event(NULL, event);
// }
MDNSResponder::MDNSResponder() :results(NULL) {}
MDNSResponder::~MDNSResponder() {
@ -65,7 +65,7 @@ bool MDNSResponder::begin(const char* hostName){
log_e("Failed starting MDNS");
return false;
}
WiFi.onEvent(_on_sys_event);
//WiFi.onEvent(_on_sys_event);
_hostname = hostName;
_hostname.toLowerCase();
if(mdns_hostname_set(hostName)) {
@ -111,10 +111,10 @@ void MDNSResponder::disableArduino(){
}
}
void MDNSResponder::enableWorkstation(wifi_interface_t interface){
void MDNSResponder::enableWorkstation(esp_interface_t interface){
char winstance[21+_hostname.length()];
uint8_t mac[6];
esp_wifi_get_mac(interface, mac);
esp_wifi_get_mac((wifi_interface_t)interface, mac);
sprintf(winstance, "%s [%02x:%02x:%02x:%02x:%02x:%02x]", _hostname.c_str(), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
if(mdns_service_add(NULL, "_workstation", "_tcp", 9, NULL, 0)) {
@ -173,7 +173,7 @@ bool MDNSResponder::addServiceTxt(char *name, char *proto, char *key, char *valu
}
IPAddress MDNSResponder::queryHost(char *host, uint32_t timeout){
struct ip4_addr addr;
esp_ip4_addr_t addr;
addr.addr = 0;
esp_err_t err = mdns_query_a(host, timeout, &addr);

View File

@ -84,7 +84,7 @@ public:
void enableArduino(uint16_t port=3232, bool auth=false);
void disableArduino();
void enableWorkstation(wifi_interface_t interface=WIFI_IF_STA);
void enableWorkstation(esp_interface_t interface=ESP_IF_WIFI_STA);
void disableWorkstation();
IPAddress queryHost(char *host, uint32_t timeout=2000);

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

@ -0,0 +1,4 @@
.pio
.vscode
mklittlefs.exe
mklittlefs

View File

@ -0,0 +1,68 @@
# How to run on PlatformIO IDE
- Download and extract to this project root a **mklittlefs** executable for your OS [from a zipped binary here](https://github.com/earlephilhower/mklittlefs/releases)
- Open **LITTLEFS_PlatformIO** folder
- Run PlatformIO project task: **Upload Filesystem Image**
- Run PlatformIO project task: **Upload and Monitor**
- You will see a Serial output like:
```
--- Miniterm on COM5 115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (Snfigsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10044
load:0x40080400,len:5872
entry 0x400806ac
Listing directory: /
FILE: /file1.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
DIR : /testfolder LAST WRITE: 2020-10-06 15:10:33
Creating Dir: /mydir
Dir created
Writing file: /mydir/hello2.txt
- file written
Listing directory: /
FILE: /file1.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
DIR : /mydir LAST WRITE: 1970-01-01 00:00:00
Listing directory: /mydir
FILE: /mydir/hello2.txt SIZE: 6 LAST WRITE: 1970-01-01 00:00:00
DIR : /testfolder LAST WRITE: 2020-10-06 15:10:33
Listing directory: /testfolder
FILE: /testfolder/test2.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
Deleting file: /mydir/hello2.txt
- file deleted
Removing Dir: /mydir
Dir removed
Listing directory: /
FILE: /file1.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
DIR : /testfolder LAST WRITE: 2020-10-06 15:10:33
Listing directory: /testfolder
FILE: /testfolder/test2.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
Writing file: /hello.txt
- file written
Appending to file: /hello.txt
- message appended
Reading file: /hello.txt
- read from file:
Hello World!
Renaming file /hello.txt to /foo.txt
- file renamed
Reading file: /foo.txt
- read from file:
Hello World!
Deleting file: /foo.txt
- file deleted
Testing file I/O with /test.txt
- writing................................................................
- 1048576 bytes written in 12006 ms
- reading................................................................
- 1048576 bytes read in 547 ms
Deleting file: /test.txt
- file deleted
Test complete
```
- If you have a module with more than 4MB flash, you can uncomment **partitions_custom.csv** in **platformio.ini** and modify the csv file accordingly

View File

@ -0,0 +1 @@
aaa

View File

@ -0,0 +1,2 @@
Import("env")
env.Replace( MKSPIFFSTOOL=env.get("PROJECT_DIR") + '/mklittlefs' )

View File

@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
ota_0, app, ota_0, 0x10000, 0x1A0000,
ota_1, app, ota_1, , 0x1A0000,
otadata, data, ota, 0x350000, 0x2000,
nvs, data, nvs, , 0x6000,
data, data, spiffs, , 0xA8000,
1 # Name Type SubType Offset Size Flags
2 ota_0 app ota_0 0x10000 0x1A0000
3 ota_1 app ota_1 0x1A0000
4 otadata data ota 0x350000 0x2000
5 nvs data nvs 0x6000
6 data data spiffs 0xA8000

View File

@ -0,0 +1,35 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = esp32
[env]
framework = arduino
[env:esp32]
platform = espressif32
;platform = https://github.com/platformio/platform-espressif32.git
;board_build.mcu = esp32
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
build_flags =
${env.build_flags}
-D=${PIOENV}
;-D CONFIG_LITTLEFS_FOR_IDF_3_2
lib_deps = https://github.com/lorol/LITTLEFS.git
board = esp32dev
;board_build.partitions = partitions_custom.csv
monitor_filters = esp32_exception_decoder
monitor_speed = 115200
extra_scripts = ./littlefsbuilder.py

View File

@ -0,0 +1,282 @@
#include <Arduino.h>
#include "FS.h"
#include <LITTLEFS.h>
#include <time.h>
/* You only need to format LITTLEFS the first time you run a
test or else use the LITTLEFS plugin to create a partition
https://github.com/lorol/arduino-esp32littlefs-plugin */
#define FORMAT_LITTLEFS_IF_FAILED true
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\r\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("- failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println(" - not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.print(file.name());
time_t t= file.getLastWrite();
struct tm * tmstruct = localtime(&t);
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
if(levels){
listDir(fs, file.name(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.print(file.size());
time_t t= file.getLastWrite();
struct tm * tmstruct = localtime(&t);
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
}
file = root.openNextFile();
}
}
void createDir(fs::FS &fs, const char * path){
Serial.printf("Creating Dir: %s\n", path);
if(fs.mkdir(path)){
Serial.println("Dir created");
} else {
Serial.println("mkdir failed");
}
}
void removeDir(fs::FS &fs, const char * path){
Serial.printf("Removing Dir: %s\n", path);
if(fs.rmdir(path)){
Serial.println("Dir removed");
} else {
Serial.println("rmdir failed");
}
}
void readFile(fs::FS &fs, const char * path){
Serial.printf("Reading file: %s\r\n", path);
File file = fs.open(path);
if(!file || file.isDirectory()){
Serial.println("- failed to open file for reading");
return;
}
Serial.println("- read from file:");
while(file.available()){
Serial.write(file.read());
}
file.close();
}
void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Writing file: %s\r\n", path);
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("- failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("- file written");
} else {
Serial.println("- write failed");
}
file.close();
}
void appendFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Appending to file: %s\r\n", path);
File file = fs.open(path, FILE_APPEND);
if(!file){
Serial.println("- failed to open file for appending");
return;
}
if(file.print(message)){
Serial.println("- message appended");
} else {
Serial.println("- append failed");
}
file.close();
}
void renameFile(fs::FS &fs, const char * path1, const char * path2){
Serial.printf("Renaming file %s to %s\r\n", path1, path2);
if (fs.rename(path1, path2)) {
Serial.println("- file renamed");
} else {
Serial.println("- rename failed");
}
}
void deleteFile(fs::FS &fs, const char * path){
Serial.printf("Deleting file: %s\r\n", path);
if(fs.remove(path)){
Serial.println("- file deleted");
} else {
Serial.println("- delete failed");
}
}
// SPIFFS-like write and delete file
// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60
void writeFile2(fs::FS &fs, const char * path, const char * message){
if(!fs.exists(path)){
if (strchr(path, '/')) {
Serial.printf("Create missing folders of: %s\r\n", path);
char *pathStr = strdup(path);
if (pathStr) {
char *ptr = strchr(pathStr, '/');
while (ptr) {
*ptr = 0;
fs.mkdir(pathStr);
*ptr = '/';
ptr = strchr(ptr+1, '/');
}
}
free(pathStr);
}
}
Serial.printf("Writing file to: %s\r\n", path);
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("- failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("- file written");
} else {
Serial.println("- write failed");
}
file.close();
}
// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149
void deleteFile2(fs::FS &fs, const char * path){
Serial.printf("Deleting file and empty folders on path: %s\r\n", path);
if(fs.remove(path)){
Serial.println("- file deleted");
} else {
Serial.println("- delete failed");
}
char *pathStr = strdup(path);
if (pathStr) {
char *ptr = strrchr(pathStr, '/');
if (ptr) {
Serial.printf("Removing all empty folders on path: %s\r\n", path);
}
while (ptr) {
*ptr = 0;
fs.rmdir(pathStr);
ptr = strrchr(pathStr, '/');
}
free(pathStr);
}
}
void testFileIO(fs::FS &fs, const char * path){
Serial.printf("Testing file I/O with %s\r\n", path);
static uint8_t buf[512];
size_t len = 0;
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("- failed to open file for writing");
return;
}
size_t i;
Serial.print("- writing" );
uint32_t start = millis();
for(i=0; i<2048; i++){
if ((i & 0x001F) == 0x001F){
Serial.print(".");
}
file.write(buf, 512);
}
Serial.println("");
uint32_t end = millis() - start;
Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end);
file.close();
file = fs.open(path);
start = millis();
end = start;
i = 0;
if(file && !file.isDirectory()){
len = file.size();
size_t flen = len;
start = millis();
Serial.print("- reading" );
while(len){
size_t toRead = len;
if(toRead > 512){
toRead = 512;
}
file.read(buf, toRead);
if ((i++ & 0x001F) == 0x001F){
Serial.print(".");
}
len -= toRead;
}
Serial.println("");
end = millis() - start;
Serial.printf("- %u bytes read in %u ms\r\n", flen, end);
file.close();
} else {
Serial.println("- failed to open file for reading");
}
}
void setup(){
Serial.begin(115200);
if(!LITTLEFS.begin(FORMAT_LITTLEFS_IF_FAILED)){
Serial.println("LITTLEFS Mount Failed");
return;
}
listDir(LITTLEFS, "/", 0);
createDir(LITTLEFS, "/mydir");
writeFile(LITTLEFS, "/mydir/hello2.txt", "Hello2");
//writeFile(LITTLEFS, "/mydir/newdir2/newdir3/hello3.txt", "Hello3");
writeFile2(LITTLEFS, "/mydir/newdir2/newdir3/hello3.txt", "Hello3");
listDir(LITTLEFS, "/", 3);
deleteFile(LITTLEFS, "/mydir/hello2.txt");
//deleteFile(LITTLEFS, "/mydir/newdir2/newdir3/hello3.txt");
deleteFile2(LITTLEFS, "/mydir/newdir2/newdir3/hello3.txt");
removeDir(LITTLEFS, "/mydir");
listDir(LITTLEFS, "/", 3);
writeFile(LITTLEFS, "/hello.txt", "Hello ");
appendFile(LITTLEFS, "/hello.txt", "World!\r\n");
readFile(LITTLEFS, "/hello.txt");
renameFile(LITTLEFS, "/hello.txt", "/foo.txt");
readFile(LITTLEFS, "/foo.txt");
deleteFile(LITTLEFS, "/foo.txt");
testFileIO(LITTLEFS, "/test.txt");
deleteFile(LITTLEFS, "/test.txt");
Serial.println( "Test complete" );
}
void loop(){
}

View File

@ -0,0 +1,272 @@
#include <Arduino.h>
#include "FS.h"
#include <LITTLEFS.h>
/* You only need to format LITTLEFS the first time you run a
test or else use the LITTLEFS plugin to create a partition
https://github.com/lorol/arduino-esp32littlefs-plugin */
#define FORMAT_LITTLEFS_IF_FAILED true
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\r\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("- failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println(" - not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
if(levels){
listDir(fs, file.name(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print("\tSIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void createDir(fs::FS &fs, const char * path){
Serial.printf("Creating Dir: %s\n", path);
if(fs.mkdir(path)){
Serial.println("Dir created");
} else {
Serial.println("mkdir failed");
}
}
void removeDir(fs::FS &fs, const char * path){
Serial.printf("Removing Dir: %s\n", path);
if(fs.rmdir(path)){
Serial.println("Dir removed");
} else {
Serial.println("rmdir failed");
}
}
void readFile(fs::FS &fs, const char * path){
Serial.printf("Reading file: %s\r\n", path);
File file = fs.open(path);
if(!file || file.isDirectory()){
Serial.println("- failed to open file for reading");
return;
}
Serial.println("- read from file:");
while(file.available()){
Serial.write(file.read());
}
file.close();
}
void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Writing file: %s\r\n", path);
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("- failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("- file written");
} else {
Serial.println("- write failed");
}
file.close();
}
void appendFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Appending to file: %s\r\n", path);
File file = fs.open(path, FILE_APPEND);
if(!file){
Serial.println("- failed to open file for appending");
return;
}
if(file.print(message)){
Serial.println("- message appended");
} else {
Serial.println("- append failed");
}
file.close();
}
void renameFile(fs::FS &fs, const char * path1, const char * path2){
Serial.printf("Renaming file %s to %s\r\n", path1, path2);
if (fs.rename(path1, path2)) {
Serial.println("- file renamed");
} else {
Serial.println("- rename failed");
}
}
void deleteFile(fs::FS &fs, const char * path){
Serial.printf("Deleting file: %s\r\n", path);
if(fs.remove(path)){
Serial.println("- file deleted");
} else {
Serial.println("- delete failed");
}
}
// SPIFFS-like write and delete file
// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60
void writeFile2(fs::FS &fs, const char * path, const char * message){
if(!fs.exists(path)){
if (strchr(path, '/')) {
Serial.printf("Create missing folders of: %s\r\n", path);
char *pathStr = strdup(path);
if (pathStr) {
char *ptr = strchr(pathStr, '/');
while (ptr) {
*ptr = 0;
fs.mkdir(pathStr);
*ptr = '/';
ptr = strchr(ptr+1, '/');
}
}
free(pathStr);
}
}
Serial.printf("Writing file to: %s\r\n", path);
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("- failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("- file written");
} else {
Serial.println("- write failed");
}
file.close();
}
// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149
void deleteFile2(fs::FS &fs, const char * path){
Serial.printf("Deleting file and empty folders on path: %s\r\n", path);
if(fs.remove(path)){
Serial.println("- file deleted");
} else {
Serial.println("- delete failed");
}
char *pathStr = strdup(path);
if (pathStr) {
char *ptr = strrchr(pathStr, '/');
if (ptr) {
Serial.printf("Removing all empty folders on path: %s\r\n", path);
}
while (ptr) {
*ptr = 0;
fs.rmdir(pathStr);
ptr = strrchr(pathStr, '/');
}
free(pathStr);
}
}
void testFileIO(fs::FS &fs, const char * path){
Serial.printf("Testing file I/O with %s\r\n", path);
static uint8_t buf[512];
size_t len = 0;
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("- failed to open file for writing");
return;
}
size_t i;
Serial.print("- writing" );
uint32_t start = millis();
for(i=0; i<2048; i++){
if ((i & 0x001F) == 0x001F){
Serial.print(".");
}
file.write(buf, 512);
}
Serial.println("");
uint32_t end = millis() - start;
Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end);
file.close();
file = fs.open(path);
start = millis();
end = start;
i = 0;
if(file && !file.isDirectory()){
len = file.size();
size_t flen = len;
start = millis();
Serial.print("- reading" );
while(len){
size_t toRead = len;
if(toRead > 512){
toRead = 512;
}
file.read(buf, toRead);
if ((i++ & 0x001F) == 0x001F){
Serial.print(".");
}
len -= toRead;
}
Serial.println("");
end = millis() - start;
Serial.printf("- %u bytes read in %u ms\r\n", flen, end);
file.close();
} else {
Serial.println("- failed to open file for reading");
}
}
void setup(){
Serial.begin(115200);
if(!LITTLEFS.begin(FORMAT_LITTLEFS_IF_FAILED)){
Serial.println("LITTLEFS Mount Failed");
return;
}
Serial.println( "SPIFFS-like write file to new path and delete it w/folders" );
writeFile2(LITTLEFS, "/new1/new2/new3/hello3.txt", "Hello3");
listDir(LITTLEFS, "/", 3);
deleteFile2(LITTLEFS, "/new1/new2/new3/hello3.txt");
listDir(LITTLEFS, "/", 3);
createDir(LITTLEFS, "/mydir");
writeFile(LITTLEFS, "/mydir/hello2.txt", "Hello2");
listDir(LITTLEFS, "/", 1);
deleteFile(LITTLEFS, "/mydir/hello2.txt");
removeDir(LITTLEFS, "/mydir");
listDir(LITTLEFS, "/", 1);
writeFile(LITTLEFS, "/hello.txt", "Hello ");
appendFile(LITTLEFS, "/hello.txt", "World!\r\n");
readFile(LITTLEFS, "/hello.txt");
renameFile(LITTLEFS, "/hello.txt", "/foo.txt");
readFile(LITTLEFS, "/foo.txt");
deleteFile(LITTLEFS, "/foo.txt");
testFileIO(LITTLEFS, "/test.txt");
deleteFile(LITTLEFS, "/test.txt");
Serial.println( "Test complete" );
}
void loop(){
}

View File

@ -0,0 +1,214 @@
#include "FS.h"
//#include "SPIFFS.h"
#include "LITTLEFS.h"
#include <time.h>
#include <WiFi.h>
#define SPIFFS LITTLEFS
/* This examples uses "quick re-define" of SPIFFS to run
an existing sketch with LITTLEFS instead of SPIFFS
You only need to format LITTLEFS the first time you run a
test or else use the LITTLEFS plugin to create a partition
https://github.com/lorol/arduino-esp32littlefs-plugin */
#define FORMAT_LITTLEFS_IF_FAILED true
const char* ssid = "yourssid";
const char* password = "yourpass";
long timezone = 1;
byte daysavetime = 1;
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("Failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.print (file.name());
time_t t= file.getLastWrite();
struct tm * tmstruct = localtime(&t);
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
if(levels){
listDir(fs, file.name(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.print(file.size());
time_t t= file.getLastWrite();
struct tm * tmstruct = localtime(&t);
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
}
file = root.openNextFile();
}
}
void createDir(fs::FS &fs, const char * path){
Serial.printf("Creating Dir: %s\n", path);
if(fs.mkdir(path)){
Serial.println("Dir created");
} else {
Serial.println("mkdir failed");
}
}
void removeDir(fs::FS &fs, const char * path){
Serial.printf("Removing Dir: %s\n", path);
if(fs.rmdir(path)){
Serial.println("Dir removed");
} else {
Serial.println("rmdir failed");
}
}
void readFile(fs::FS &fs, const char * path){
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if(!file){
Serial.println("Failed to open file for reading");
return;
}
Serial.print("Read from file: ");
while(file.available()){
Serial.write(file.read());
}
file.close();
}
void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Writing file: %s\n", path);
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("Failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("File written");
} else {
Serial.println("Write failed");
}
file.close();
}
void appendFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Appending to file: %s\n", path);
File file = fs.open(path, FILE_APPEND);
if(!file){
Serial.println("Failed to open file for appending");
return;
}
if(file.print(message)){
Serial.println("Message appended");
} else {
Serial.println("Append failed");
}
file.close();
}
void renameFile(fs::FS &fs, const char * path1, const char * path2){
Serial.printf("Renaming file %s to %s\n", path1, path2);
if (fs.rename(path1, path2)) {
Serial.println("File renamed");
} else {
Serial.println("Rename failed");
}
}
void deleteFile(fs::FS &fs, const char * path){
Serial.printf("Deleting file: %s\n", path);
if(fs.remove(path)){
Serial.println("File deleted");
} else {
Serial.println("Delete failed");
}
}
void setup(){
Serial.begin(115200);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Contacting Time Server");
configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
struct tm tmstruct ;
delay(2000);
tmstruct.tm_year = 0;
getLocalTime(&tmstruct, 5000);
Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct.tm_year)+1900,( tmstruct.tm_mon)+1, tmstruct.tm_mday,tmstruct.tm_hour , tmstruct.tm_min, tmstruct.tm_sec);
Serial.println("");
if(!SPIFFS.begin(FORMAT_LITTLEFS_IF_FAILED)){
Serial.println("LITTLEFS Mount Failed");
return;
}
Serial.println("----list 1----");
listDir(SPIFFS, "/", 1);
Serial.println("----remove old dir----");
removeDir(SPIFFS, "/mydir");
Serial.println("----create a new dir----");
createDir(SPIFFS, "/mydir");
Serial.println("----remove the new dir----");
removeDir(SPIFFS, "/mydir");
Serial.println("----create the new again----");
createDir(SPIFFS, "/mydir");
Serial.println("----create and work with file----");
writeFile(SPIFFS, "/mydir/hello.txt", "Hello ");
appendFile(SPIFFS, "/mydir/hello.txt", "World!\n");
Serial.println("----list 2----");
listDir(SPIFFS, "/", 1);
Serial.println("----attempt to remove dir w/ file----");
removeDir(SPIFFS, "/mydir");
Serial.println("----remove dir after deleting file----");
deleteFile(SPIFFS, "/mydir/hello.txt");
removeDir(SPIFFS, "/mydir");
Serial.println("----list 3----");
listDir(SPIFFS, "/", 1);
Serial.println( "Test complete" );
}
void loop(){
}

View File

@ -0,0 +1,9 @@
name=LITTLEFS
version=2.0
author=
maintainer=
sentence=LittleFS for esp32
paragraph=LittleFS for esp32
category=Data Storage
url=
architectures=esp32

View File

@ -0,0 +1,107 @@
// Copyright 2015-2020 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.
static constexpr const char LFS_NAME[] = "spiffs";
#include "vfs_api.h"
extern "C" {
#include <sys/unistd.h>
#include <sys/stat.h>
#include <dirent.h>
#undef B110
#undef B1000000
#include "esp_littlefs.h"
}
#include "LITTLEFS.h"
using namespace fs;
LITTLEFSFS::LITTLEFSFS() : FS(FSImplPtr(new VFSImpl()))
{
}
bool LITTLEFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFilesUnused)
{
if(esp_littlefs_mounted(LFS_NAME)){
log_w("LITTLEFS Already Mounted!");
return true;
}
esp_vfs_littlefs_conf_t conf = {
.base_path = basePath,
.partition_label = LFS_NAME,
.format_if_mount_failed = false
};
esp_err_t err = esp_vfs_littlefs_register(&conf);
if(err == ESP_FAIL && formatOnFail){
if(format()){
err = esp_vfs_littlefs_register(&conf);
}
}
if(err != ESP_OK){
log_e("Mounting LITTLEFS failed! Error: %d", err);
return false;
}
_impl->mountpoint(basePath);
return true;
}
void LITTLEFSFS::end()
{
if(esp_littlefs_mounted(LFS_NAME)){
esp_err_t err = esp_vfs_littlefs_unregister(LFS_NAME);
if(err){
log_e("Unmounting LITTLEFS failed! Error: %d", err);
return;
}
_impl->mountpoint(NULL);
}
}
bool LITTLEFSFS::format()
{
disableCore0WDT();
esp_err_t err = esp_littlefs_format(LFS_NAME);
enableCore0WDT();
if(err){
log_e("Formatting LITTLEFS failed! Error: %d", err);
return false;
}
return true;
}
size_t LITTLEFSFS::totalBytes()
{
size_t total,used;
if(esp_littlefs_info(LFS_NAME, &total, &used)){
return 0;
}
return total;
}
size_t LITTLEFSFS::usedBytes()
{
size_t total,used;
if(esp_littlefs_info(LFS_NAME, &total, &used)){
return 0;
}
return used;
}
LITTLEFSFS LITTLEFS;

View File

@ -0,0 +1,38 @@
// Copyright 2015-2020 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.
#ifndef _LITTLEFS_H_
#define _LITTLEFS_H_
#include "FS.h"
namespace fs
{
class LITTLEFSFS : public FS
{
public:
LITTLEFSFS();
bool begin(bool formatOnFail=false, const char * basePath="/littlefs", uint8_t maxOpenFiles=5);
bool format();
size_t totalBytes();
size_t usedBytes();
void end();
};
}
extern fs::LITTLEFSFS LITTLEFS;
#endif

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