#include "esp_log.h"
#include "stdio.h"
#include "sdkconfig.h"
#define TAG "Teste Log"
// extern "C"
//{
// void app_main();
//}
void app_main()
{
printf("- Teste -\n");
esp_log_level_set(TAG, ESP_LOG_VERBOSE);
ESP_LOGW(TAG, "AppMain -> Início.");
ESP_LOGI(TAG, "AppMain -> Início.");
ESP_LOGE(TAG, "AppMain -> Início.");
ESP_LOGD(TAG, "AppMain -> Início.");
ESP_LOGV(TAG, "AppMain -> Início.");
printf("- Teste -\n");
}
/* sdkconfig.h
#define CONFIG_LOG_DEFAULT_LEVEL_VERBOSE 1
#define CONFIG_LOG_DEFAULT_LEVEL 5
#define CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE 1
#define CONFIG_LOG_MAXIMUM_LEVEL 5
#define CONFIG_LOG_COLORS 1
#define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 1
*/
/* The example of ESP-IDF
*
* This sample code is in the public domain.
*/
/*
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "cJSON.h"
#include "stdio.h"
#include "sdkconfig.h"
#define TAG "JSON"
void JSON_Print(cJSON *element) {
if (element->type == cJSON_Invalid) ESP_LOGI(TAG, "cJSON_Invalid");
if (element->type == cJSON_False) ESP_LOGI(TAG, "cJSON_False");
if (element->type == cJSON_True) ESP_LOGI(TAG, "cJSON_True");
if (element->type == cJSON_NULL) ESP_LOGI(TAG, "cJSON_NULL");
if (element->type == cJSON_Number) ESP_LOGI(TAG, "cJSON_Number int=%d double=%f", element->valueint, element->valuedouble);
if (element->type == cJSON_String) ESP_LOGI(TAG, "cJSON_String string=%s", element->valuestring);
if (element->type == cJSON_Array) ESP_LOGI(TAG, "cJSON_Array");
if (element->type == cJSON_Object) ESP_LOGI(TAG, "cJSON_Object");
if ( element->type == cJSON_Raw) ESP_LOGI(TAG, "cJSON_Raw");
}
void app_main()
{
esp_log_level_set(TAG, ESP_LOG_VERBOSE);
printf("- Teste -\n");
ESP_LOGI(TAG, "Serialize.....");
cJSON *root;
root = cJSON_CreateArray();
cJSON *element;
element = cJSON_CreateString("abc");
cJSON_AddItemToArray(root, element);
element = cJSON_CreateNumber(123);
cJSON_AddItemToArray(root, element);
element = cJSON_CreateTrue();
cJSON_AddItemToArray(root, element);
element = cJSON_CreateFalse();
cJSON_AddItemToArray(root, element);
element = cJSON_CreateNull();
cJSON_AddItemToArray(root, element);
char *my_json_string = cJSON_Print(root);
ESP_LOGI(TAG, "my_json_string:%s",my_json_string);
cJSON_Delete(root);
ESP_LOGI(TAG, "Deserialize.....");
cJSON *root2 = cJSON_Parse(my_json_string);
int root2_array_size = cJSON_GetArraySize(root2);
ESP_LOGI(TAG, "root2_array_size=%d", root2_array_size);
for (int i=0;i<root2_array_size;i++) {
cJSON *element2 = cJSON_GetArrayItem(root2, i);
JSON_Print(element2);
}
cJSON_Delete(root2);
// Buffers returned by cJSON_Print must be freed by the caller.
// Please use the proper API (cJSON_free) rather than directly calling stdlib free.
cJSON_free(my_json_string);
printf("- Teste -\n");
}
#include <stdio.h>
#include <string.h>
#include "esp_sleep.h"
#include "esp_attr.h"
#include "rom/rtc.h"
#include "rom/ets_sys.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/rtc_io_reg.h"
#include "soc/uart_reg.h"
#include "soc/timer_group_reg.h"
// Pin used for pulse counting
// GPIO0 is RTC_GPIO11 (see esp32_chip_pin_list_en.pdf)
#define PULSE_CNT_GPIO_NUM 0
#define PULSE_CNT_RTC_GPIO_NUM 11
#define PULSE_CNT_IS_LOW() \
((REG_GET_FIELD(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT) \
& BIT(PULSE_CNT_RTC_GPIO_NUM)) == 0)
// Pulse counter value, stored in RTC_SLOW_MEM
static size_t RTC_DATA_ATTR s_pulse_count;
static size_t RTC_DATA_ATTR s_max_pulse_count;
// Function which runs after exit from deep sleep
static void RTC_IRAM_ATTR wake_stub();
void app_main(void)
{
if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
printf("Wake up from deep sleep\n");
printf("Pulse count=%d\n", s_pulse_count);
} else {
printf("Not a deep sleep wake up\n");
}
s_pulse_count = 0;
s_max_pulse_count = 20;
printf("Going to deep sleep in 1 second\n");
printf("Will wake up after %d pulses\n", s_max_pulse_count);
vTaskDelay(1000/portTICK_PERIOD_MS);
// Set the wake stub function
esp_set_deep_sleep_wake_stub(&wake_stub);
// Wake up on low logic level
ESP_ERROR_CHECK( esp_sleep_enable_ext1_wakeup(
1LL << PULSE_CNT_GPIO_NUM, ESP_EXT1_WAKEUP_ALL_LOW) );
// Enter deep sleep
esp_deep_sleep_start();
}
static const char RTC_RODATA_ATTR wake_fmt_str[] = "count=%d\n";
static const char RTC_RODATA_ATTR sleep_fmt_str[] = "sleeping\n";
static void RTC_IRAM_ATTR wake_stub()
{
// Increment the pulse counter
s_pulse_count++;
// and print the pulse counter value:
ets_printf(wake_fmt_str, s_pulse_count);
if (s_pulse_count >= s_max_pulse_count) {
// On revision 0 of ESP32, this function must be called:
esp_default_wake_deep_sleep();
// Return from the wake stub function to continue
// booting the firmware.
return;
}
// Pulse count is <s_max_pulse_count, go back to sleep
// and wait for more pulses.
// Wait for pin level to be high.
// If we go to sleep when the pin is still low, the chip
// will wake up again immediately. Hardware doesn't have
// edge trigger support for deep sleep wakeup.
do {
while (PULSE_CNT_IS_LOW()) {
// feed the watchdog
REG_WRITE(TIMG_WDTFEED_REG(0), 1);
}
// debounce, 10ms
ets_delay_us(10000);
} while (PULSE_CNT_IS_LOW());
// Print status
ets_printf(sleep_fmt_str);
// Wait for UART to end transmitting.
while (REG_GET_FIELD(UART_STATUS_REG(0), UART_ST_UTX_OUT)) {
;
}
// Set the pointer of the wake stub function.
REG_WRITE(RTC_ENTRY_ADDR_REG, (uint32_t)&wake_stub);
// Go to sleep.
CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SLEEP_EN);
SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SLEEP_EN);
// A few CPU cycles may be necessary for the sleep to start...
while (true) {
;
}
// never reaches here.
}
*/