esp_err_t esp_modem_dce_hang_up(modem_dce_t *dce) { modem_dte_t *dte = dce->dte; dce->handle_line = esp_modem_dce_handle_response_default; DCE_CHECK(dte->send_cmd(dte, "ATH\r", MODEM_COMMAND_TIMEOUT_HANG_UP) == ESP_OK, "send command failed", err); DCE_CHECK(dce->state == MODEM_STATE_SUCCESS, "hang up failed", err); ESP_LOGD(DCE_TAG, "hang up ok"); return ESP_OK; err: return ESP_FAIL; }
static int http_on_headers_complete(http_parser *parser) { esp_http_client_handle_t client = parser->data; client->response->status_code = parser->status_code; client->response->data_offset = parser->nread; client->response->content_length = parser->content_length; client->response->data_process = 0; ESP_LOGD(TAG, "http_on_headers_complete, status=%d, offset=%d, nread=%d", parser->status_code, client->response->data_offset, parser->nread); client->state = HTTP_STATE_RES_COMPLETE_HEADER; return 0; }
/** * @brief Begin a new %I2C transaction. * * Begin a transaction by adding an %I2C start to the queue. * @return N/A. */ void I2C::beginTransaction() { if (debug) { ESP_LOGD(LOG_TAG, "beginTransaction()"); } m_cmd = ::i2c_cmd_link_create(); esp_err_t errRc = ::i2c_master_start(m_cmd); if (errRc != ESP_OK) { ESP_LOGE(LOG_TAG, "i2c_master_start: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } m_directionKnown = false; } // beginTransaction
/** * @brief Create a %BLE Service. * * With a %BLE server, we can host one or more services. Invoking this function causes the creation of a definition * of a new service. Every service must have a unique UUID. * @param [in] uuid The UUID of the new service. * @param [in] numHandles The maximum number of handles associated with this service. * @param [in] inst_id With multiple services with the same UUID we need to provide inst_id value different for each service. * @return A reference to the new service object. */ BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles, uint8_t inst_id) { ESP_LOGD(LOG_TAG, ">> createService - %s", uuid.toString().c_str()); m_semaphoreCreateEvt.take("createService"); // Check that a service with the supplied UUID does not already exist. if (m_serviceMap.getByUUID(uuid) != nullptr) { ESP_LOGW(LOG_TAG, "<< Attempt to create a new service with uuid %s but a service with that UUID already exists.", uuid.toString().c_str()); } BLEService* pService = new BLEService(uuid, numHandles); pService->m_instId = inst_id; m_serviceMap.setByUUID(uuid, pService); // Save a reference to this service being on this server. pService->executeCreate(this); // Perform the API calls to actually create the service. m_semaphoreCreateEvt.wait("createService"); ESP_LOGD(LOG_TAG, "<< createService"); return pService; } // createService
/** * @brief Publish a message. * Publish a message on the given topic. * * @param [in] topic The topic against which we wish to publish. * @param [in] payload The payload of the message we wish to publish. * @param [in] qos The quality of service for the publish. * @return N/A. */ void AWS::publish(std::string topic, std::string payload, QoS qos) { IoT_Publish_Message_Params message; message.payload = (void *)payload.data(); message.payloadLen = payload.length(); message.qos = qos; message.isRetained = 0; IoT_Error_t err = ::aws_iot_mqtt_publish(&m_client, topic.c_str(), topic.length(), &message); if (err != SUCCESS) { ESP_LOGD(tag, "aws_iot_mqtt_publish: error=%d", err); } } // publish
esp_err_t esp_modem_dce_store_profile(modem_dce_t *dce) { modem_dte_t *dte = dce->dte; dce->handle_line = esp_modem_dce_handle_response_default; DCE_CHECK(dte->send_cmd(dte, "AT&W\r", MODEM_COMMAND_TIMEOUT_DEFAULT) == ESP_OK, "send command failed", err); DCE_CHECK(dce->state == MODEM_STATE_SUCCESS, "save settings failed", err); ESP_LOGD(DCE_TAG, "save settings ok"); return ESP_OK; err: return ESP_FAIL; }
void run(void *data) { ESP_LOGD(tag, "Testing curl ..."); RESTClient client; /** * Test POST */ RESTTimings *timings = client.getTimings(); client.setURL("https://httpbin.org/post"); client.addHeader("Content-Type", "application/json"); client.post("hello world!"); ESP_LOGD(tag, "Result: %s", client.getResponse().c_str()); timings->refresh(); ESP_LOGD(tag, "timings: %s", timings->toString().c_str()); printf("Tests done\n"); return; }
STATIC mp_obj_t get_wlan(size_t n_args, const mp_obj_t *args) { static int initialized = 0; if (!initialized) { wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_LOGD("modnetwork", "Initializing WiFi"); ESP_EXCEPTIONS( esp_wifi_init(&cfg) ); ESP_EXCEPTIONS( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); ESP_LOGD("modnetwork", "Initialized"); initialized = 1; } int idx = (n_args > 0) ? mp_obj_get_int(args[0]) : WIFI_IF_STA; if (idx == WIFI_IF_STA) { return MP_OBJ_FROM_PTR(&wlan_sta_obj); } else if (idx == WIFI_IF_AP) { return MP_OBJ_FROM_PTR(&wlan_ap_obj); } else { mp_raise_ValueError("invalid WLAN interface identifier"); } }
/** * @brief Accept an incoming connection. * @private * * Block waiting for an incoming connection and accept it when it arrives. The new * socket is placed on a queue and a semaphore signaled that a new client is available. */ /* static */ void SockServ::acceptTask(void* data) { SockServ* pSockServ = (SockServ*)data; try { while(1) { ESP_LOGD(LOG_TAG, "Waiting on accept") Socket tempSock = pSockServ->m_serverSocket.accept(); if (!tempSock.isValid()) { continue; } pSockServ->m_clientSet.insert(tempSock); xQueueSendToBack(pSockServ->m_acceptQueue, &tempSock, portMAX_DELAY); pSockServ->m_clientSemaphore.give(); } } catch(std::exception e) { ESP_LOGD(LOG_TAG, "acceptTask ending"); pSockServ->m_clientSemaphore.give(); // Wake up any waiting clients. FreeRTOS::deleteTask(); } } // acceptTask
int httpd_recv_with_opt(httpd_req_t *r, char *buf, size_t buf_len, bool halt_after_pending) { ESP_LOGD(TAG, LOG_FMT("requested length = %d"), buf_len); size_t pending_len = 0; struct httpd_req_aux *ra = r->aux; /* First fetch pending data from local buffer */ if (ra->sd->pending_len > 0) { ESP_LOGD(TAG, LOG_FMT("pending length = %d"), ra->sd->pending_len); pending_len = httpd_recv_pending(r, buf, buf_len); buf += pending_len; buf_len -= pending_len; /* If buffer filled then no need to recv. * If asked to halt after receiving pending data then * return with received length */ if (!buf_len || halt_after_pending) { return pending_len; } } /* Receive data of remaining length */ int ret = ra->sd->recv_fn(ra->sd->handle, ra->sd->fd, buf, buf_len, 0); if (ret < 0) { ESP_LOGD(TAG, LOG_FMT("error in recv_fn")); if ((ret == HTTPD_SOCK_ERR_TIMEOUT) && (pending_len != 0)) { /* If recv() timeout occurred, but pending data is * present, return length of pending data. * This behavior is similar to that of socket recv() * function, which, in case has only partially read the * requested length, due to timeout, returns with read * length, rather than error */ return pending_len; } return ret; } ESP_LOGD(TAG, LOG_FMT("received length = %d"), ret + pending_len); return ret + pending_len; }
/** * @brief Create the service. * Create the service. * @param [in] gatts_if The handle of the GATT server interface. * @return N/A. */ void BLEService::executeCreate(BLEServer *pServer) { ESP_LOGD(LOG_TAG, ">> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: %s", getUUID().toString().c_str()); m_pServer = pServer; esp_gatt_srvc_id_t srvc_id; srvc_id.id.inst_id = 0; srvc_id.id.uuid = *m_uuid.getNative(); m_semaphoreCreateEvt.take("executeCreate"); // Take the mutex and release at event ESP_GATTS_CREATE_EVT esp_err_t errRc = ::esp_ble_gatts_create_service(getServer()->getGattsIf(), &srvc_id, 10); if (errRc != ESP_OK) { ESP_LOGE(LOG_TAG, "esp_ble_gatts_create_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; } m_semaphoreCreateEvt.wait("executeCreate"); ESP_LOGD(LOG_TAG, "<< executeCreate"); } // executeCreate
esp_err_t esp_vfs_semihost_unregister(const char* base_path) { ESP_LOGD(TAG, "Unregister semihosting driver @ '%s'", base_path); int i = 0; for (i = 0; i < CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS; i++) { if (s_semhost_ctx[i].base_path[0] != 0 && strcmp(base_path, s_semhost_ctx[i].base_path) == 0) { break; } } if (i == CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS) { return ESP_ERR_INVALID_ARG; } esp_err_t ret = esp_vfs_unregister(s_semhost_ctx[i].base_path); if (ret != ESP_OK) { return ret; } s_semhost_ctx[i].base_path[0] = 0; s_semhost_ctx[i].host_path[0] = 0; ESP_LOGD(TAG, "Unregistered semihosting driver @ '%s'", base_path); return ESP_OK; }
int check_working_socket() { int ret; #if EXAMPLE_ESP_TCP_MODE_SERVER ESP_LOGD(TAG, "check server_socket"); ret = get_socket_error_code(server_socket); if(ret != 0) { ESP_LOGW(TAG, "server socket error %d %s", ret, strerror(ret)); } if(ret == ECONNRESET) return ret; #endif ESP_LOGD(TAG, "check connect_socket"); ret = get_socket_error_code(connect_socket); if(ret != 0) { ESP_LOGW(TAG, "connect socket error %d %s", ret, strerror(ret)); } if(ret != 0) return ret; return 0; }
bool bootloader_common_erase_part_type_data(const char *list_erase, bool ota_data_erase) { const esp_partition_info_t *partitions; const char *marker; esp_err_t err; int num_partitions; bool ret = true; partitions = bootloader_mmap(ESP_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_MAX_LEN); if (!partitions) { ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", ESP_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_MAX_LEN); return false; } ESP_LOGD(TAG, "mapped partition table 0x%x at 0x%x", ESP_PARTITION_TABLE_OFFSET, (intptr_t)partitions); err = esp_partition_table_verify(partitions, true, &num_partitions); if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to verify partition table"); ret = false; } else { ESP_LOGI(TAG, "## Label Usage Offset Length Cleaned"); for (int i = 0; i < num_partitions; i++) { const esp_partition_info_t *partition = &partitions[i]; char label[sizeof(partition->label) + 1] = {0}; if (partition->type == PART_TYPE_DATA) { bool fl_ota_data_erase = false; if (ota_data_erase == true && partition->subtype == PART_SUBTYPE_DATA_OTA) { fl_ota_data_erase = true; } // partition->label is not null-terminated string. strncpy(label, (char *)&partition->label, sizeof(label) - 1); if (fl_ota_data_erase == true || (bootloader_common_label_search(list_erase, label) == true)) { err = bootloader_flash_erase_range(partition->pos.offset, partition->pos.size); if (err != ESP_OK) { ret = false; marker = "err"; } else { marker = "yes"; } } else { marker = "no"; } ESP_LOGI(TAG, "%2d %-16s data %08x %08x [%s]", i, partition->label, partition->pos.offset, partition->pos.size, marker); } } } bootloader_munmap(partitions); return ret; }
/** * @brief Get the service object corresponding to the uuid. * @param [in] uuid The UUID of the service being sought. * @return A reference to the Service or nullptr if don't know about it. * @throws BLEUuidNotFound */ BLERemoteService* BLEClient::getService(BLEUUID uuid) { ESP_LOGD(LOG_TAG, ">> getService: uuid: %s", uuid.toString().c_str()); // Design // ------ // We wish to retrieve the service given its UUID. It is possible that we have not yet asked the // device what services it has in which case we have nothing to match against. If we have not // asked the device about its services, then we do that now. Once we get the results we can then // examine the services map to see if it has the service we are looking for. if (!m_haveServices) { getServices(); } std::string uuidStr = uuid.toString(); for (auto &myPair : m_servicesMap) { if (myPair.first == uuidStr) { ESP_LOGD(LOG_TAG, "<< getService: found the service with uuid: %s", uuid.toString().c_str()); return myPair.second; } } // End of each of the services. ESP_LOGD(LOG_TAG, "<< getService: not found"); return nullptr; } // getService
/** * @brief Add a characteristic to the service. * @param [in] pCharacteristic A pointer to the characteristic to be added. */ void BLEService::addCharacteristic(BLECharacteristic* pCharacteristic) { // We maintain a mapping of characteristics owned by this service. These are managed by the // BLECharacteristicMap class instance found in m_characteristicMap. We add the characteristic // to the map and then ask the service to add the characteristic at the BLE level (ESP-IDF). // ESP_LOGD(LOG_TAG, ">> addCharacteristic()"); ESP_LOGD(LOG_TAG, "Adding characteristic (esp_ble_gatts_add_char): uuid=%s to service: %s", pCharacteristic->getUUID().toString().c_str(), toString().c_str()); // Check that we don't add the same characteristic twice. if (m_characteristicMap.getByUUID(pCharacteristic->getUUID()) != nullptr) { ESP_LOGE(LOG_TAG, "<< Attempt to add a characteristic but we already have one with this UUID"); return; } // Remember this characteristic in our map of characteristics. At this point, we can lookup by UUID // but not by handle. The handle is allocated to us on the ESP_GATTS_ADD_CHAR_EVT. m_characteristicMap.setByUUID(pCharacteristic->getUUID(), pCharacteristic); ESP_LOGD(LOG_TAG, "<< addCharacteristic()"); } // addCharacteristic
/** * @brief Return the constituent parts of the path. * If we imagine a path as composed of parts separated by slashes, then this function * returns a vector composed of the parts. For example: * * ``` * /x/y/z * ``` * will break out to: * * ``` * path[0] = "" * path[1] = "x" * path[2] = "y" * path[3] = "z" * ``` * * @return A vector of the constituent parts of the path. */ std::vector<std::string> FileSystem::pathSplit(std::string path) { std::istringstream stream(path); std::vector<std::string> ret; std::string pathPart; while (std::getline(stream, pathPart, '/')) { ret.push_back(pathPart); } // Debug for (int i = 0; i < ret.size(); i++) { ESP_LOGD(LOG_TAG, "part[%d]: %s", i, ret[i].c_str()); } return ret; } // pathSplit
/** * @brief Read a single byte from the slave. * * @param [out] byte The address into which the read byte will be stored. * @param [in] ack Whether or not we should send an ACK to the slave after reading a byte. * @return N/A. */ void I2C::read(uint8_t *byte, bool ack) { if (debug) { ESP_LOGD(LOG_TAG, "read(size=1, ack=%d)", ack); } if (m_directionKnown == false) { m_directionKnown = true; esp_err_t errRc = ::i2c_master_write_byte(m_cmd, (m_address << 1) | I2C_MASTER_READ, !ack); if (errRc != ESP_OK) { ESP_LOGE(LOG_TAG, "i2c_master_write_byte: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } } ESP_ERROR_CHECK(::i2c_master_read_byte(m_cmd, byte, ack?I2C_MASTER_ACK:I2C_MASTER_NACK)); } // readByte
/** * @brief Return the constituent parts of the path. * If we imagine a path as composed of parts separated by slashes, then this function * returns a vector composed of the parts. For example: * * ``` * /x/y/z * ``` * will break out to: * * ``` * path[0] = "" * path[1] = "x" * path[2] = "y" * path[3] = "z" * ``` * * @return A vector of the constituent parts of the path. */ std::vector<std::string> WebServer::HTTPRequest::pathSplit() { std::istringstream stream(getPath()); std::vector<std::string> ret; std::string pathPart; while(std::getline(stream, pathPart, '/')) { ret.push_back(pathPart); } // Debug for (int i=0; i<ret.size(); i++) { ESP_LOGD(tag, "part[%d]: %s", i, ret[i].c_str()); } return ret; } // pathSplit
/** * @brief Return the constituent parts of the path. * If we imagine a path as composed of parts separated by slashes, then this function * returns a vector composed of the parts. For example: * * ``` * /x/y/z * ``` * will break out to: * * ``` * path[0] = "" * path[1] = "x" * path[2] = "y" * path[3] = "z" * ``` * * @return A vector of the constituent parts of the path. */ std::vector<std::string> WebServer::HTTPRequest::pathSplit() const { std::istringstream stream(std::string(getPath(), getPathLen())); // I don't know if there's a better istringstream constructor for this std::vector<std::string> ret; std::string pathPart; while (std::getline(stream, pathPart, '/')) { ret.push_back(pathPart); } // Debug for (int i = 0; i < ret.size(); i++) { ESP_LOGD(LOG_TAG, "part[%d]: %s", i, ret[i].c_str()); } return ret; } // pathSplit
// A request Line is built from: // <method> <sp> <request-target> <sp> <HTTP-version> // void HttpParser::parseRequestLine(std::string &line) { ESP_LOGD(LOG_TAG, ">> parseRequestLine: %s [%d]", line.c_str(), line.length()); std::string::iterator it = line.begin(); // Get the method m_method = toCharToken(it, line, ' '); // Get the url m_url = toCharToken(it, line, ' '); // Get the version m_version = toCharToken(it, line, ' '); } // parseRequestLine
size_t httpd_unrecv(struct httpd_req *r, const char *buf, size_t buf_len) { struct httpd_req_aux *ra = r->aux; /* Truncate if external buf_len is greater than pending_data buffer size */ ra->sd->pending_len = MIN(sizeof(ra->sd->pending_data), buf_len); /* Copy data into internal pending_data buffer with the exact offset * such that it is right aligned inside the buffer */ size_t offset = sizeof(ra->sd->pending_data) - ra->sd->pending_len; memcpy(ra->sd->pending_data + offset, buf, ra->sd->pending_len); ESP_LOGD(TAG, LOG_FMT("length = %d"), ra->sd->pending_len); return ra->sd->pending_len; }
esp_err_t periph_sdcard_mount(esp_periph_handle_t periph) { VALIDATE_SDCARD(periph, ESP_FAIL); periph_sdcard_t *sdcard = esp_periph_get_data(periph); int ret = sdcard_mount(sdcard->root); if (ret == ESP_OK) { ESP_LOGD(TAG, "Mount SDCARD success"); sdcard->is_mounted = true; return esp_periph_send_event(periph, SDCARD_STATUS_MOUNTED, NULL, 0); } else if (ret == ESP_ERR_INVALID_STATE) { ESP_LOGD(TAG, "periph sdcard handle already mounted!"); return ESP_OK; } else { esp_periph_send_event(periph, SDCARD_STATUS_MOUNT_ERROR, NULL, 0); sdcard->is_mounted = false; ESP_LOGE(TAG, "mount sdcard error!"); return ESP_FAIL; } }
/** * @brief Process an incoming HTTP request. * * We look at the path of the request and see if it has a matching path handler. If it does, * we invoke the handler function. If it does not, we try and find a file on the file system * that would resolve to the path. * * @param [in] mgConnection The network connection on which the request was received. * @param [in] message The message representing the request. */ void WebServer::processRequest(struct mg_connection *mgConnection, struct http_message* message) { std::string uri = mgStrToString(message->uri); ESP_LOGD(tag, "WebServer::processRequest: Matching: %s", uri.c_str()); HTTPResponse httpResponse = HTTPResponse(mgConnection); httpResponse.setRootPath(getRootPath()); /* * Iterate through each of the path handlers looking for a match with the method and specified path. */ std::vector<PathHandler>::iterator it; for (it = m_pathHandlers.begin(); it != m_pathHandlers.end(); ++it) { if ((*it).match(mgStrToString(message->method), uri)) { HTTPRequest httpRequest(message); (*it).invoke(&httpRequest, &httpResponse); ESP_LOGD(tag, "Found a match!!"); return; } } // End of examine path handlers. // Because we reached here, it means that we did NOT match a handler. Now we want to attempt // to retrieve the corresponding file content. std::string filePath = httpResponse.getRootPath() + uri; ESP_LOGD(tag, "Opening file: %s", filePath.c_str()); FILE *file = fopen(filePath.c_str(), "r"); if (file != nullptr) { fseek(file, 0L, SEEK_END); size_t length = ftell(file); fseek(file, 0L, SEEK_SET); uint8_t *pData = (uint8_t *)malloc(length); fread(pData, length, 1, file); fclose(file); httpResponse.sendData(pData, length); free(pData); } else { // Handle unable to open file httpResponse.setStatus(404); // Not found httpResponse.sendData(""); } } // processRequest
/** * Become a station connecting to an existing access point. */ static void becomeStation(connection_info_t *pConnectionInfo) { ESP_LOGD(tag, "- Connecting to access point \"%s\" ...", pConnectionInfo->ssid); assert(strlen(pConnectionInfo->ssid) > 0); // If we have a static IP address information, use that. if (pConnectionInfo->ipInfo.ip.addr != 0) { ESP_LOGD(tag, " - using a static IP address of " IPSTR, IP2STR(&pConnectionInfo->ipInfo.ip)); tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &pConnectionInfo->ipInfo); } else { tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA); } ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA)); wifi_config_t sta_config; sta_config.sta.bssid_set = 0; memcpy(sta_config.sta.ssid, pConnectionInfo->ssid, SSID_SIZE); memcpy(sta_config.sta.password, pConnectionInfo->password, PASSWORD_SIZE); ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_config)); ESP_ERROR_CHECK(esp_wifi_start()); ESP_ERROR_CHECK(esp_wifi_connect()); } // becomeStation
/** * @brief Register for notifications. * @param [in] notifyCallback A callback to be invoked for a notification. If NULL is provided then we are * unregistering a notification. * @return N/A. */ void BLERemoteCharacteristic::registerForNotify( void (*notifyCallback)( BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify)) { ESP_LOGD(LOG_TAG, ">> registerForNotify(): %s", toString().c_str()); m_notifyCallback = notifyCallback; // Save the notification callback. m_semaphoreRegForNotifyEvt.take("registerForNotify"); if (notifyCallback != nullptr) { // If we have a callback function, then this is a registration. esp_err_t errRc = ::esp_ble_gattc_register_for_notify( m_pRemoteService->getClient()->getGattcIf(), *m_pRemoteService->getClient()->getPeerAddress().getNative(), getHandle() ); if (errRc != ESP_OK) { ESP_LOGE(LOG_TAG, "esp_ble_gattc_register_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } } // End Register else { // If we weren't passed a callback function, then this is an unregistration. esp_err_t errRc = ::esp_ble_gattc_unregister_for_notify( m_pRemoteService->getClient()->getGattcIf(), *m_pRemoteService->getClient()->getPeerAddress().getNative(), getHandle() ); if (errRc != ESP_OK) { ESP_LOGE(LOG_TAG, "esp_ble_gattc_unregister_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } } // End Unregister m_semaphoreRegForNotifyEvt.wait("registerForNotify"); ESP_LOGD(LOG_TAG, "<< registerForNotify()"); } // registerForNotify
void doGPS() { ESP_LOGD(tag, ">> doGPS"); uart_config_t myUartConfig; myUartConfig.baud_rate = 9600; myUartConfig.data_bits = UART_DATA_8_BITS; myUartConfig.parity = UART_PARITY_DISABLE; myUartConfig.stop_bits = UART_STOP_BITS_1; myUartConfig.flow_ctrl = UART_HW_FLOWCTRL_DISABLE; myUartConfig.rx_flow_ctrl_thresh = 120; uart_param_config(UART_NUM_1, &myUartConfig); uart_set_pin(UART_NUM_1, UART_PIN_NO_CHANGE, // TX GPS_TX_PIN, // RX UART_PIN_NO_CHANGE, // RTS UART_PIN_NO_CHANGE // CTS ); uart_driver_install(UART_NUM_1, 2048, 2048, 10, 17, NULL); while(1) { char *line = readLine(UART_NUM_1); //ESP_LOGD(tag, "%s", line); switch(minmea_sentence_id(line, false)) { case MINMEA_SENTENCE_RMC: ESP_LOGD(tag, "Sentence - MINMEA_SENTENCE_RMC"); struct minmea_sentence_rmc frame; if (minmea_parse_rmc(&frame, line)) { ESP_LOGD(tag, "$xxRMC: raw coordinates and speed: (%d/%d,%d/%d) %d/%d", frame.latitude.value, frame.latitude.scale, frame.longitude.value, frame.longitude.scale, frame.speed.value, frame.speed.scale); ESP_LOGD(tag, "$xxRMC fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d", minmea_rescale(&frame.latitude, 1000), minmea_rescale(&frame.longitude, 1000), minmea_rescale(&frame.speed, 1000)); ESP_LOGD(tag, "$xxRMC floating point degree coordinates and speed: (%f,%f) %f", minmea_tocoord(&frame.latitude), minmea_tocoord(&frame.longitude), minmea_tofloat(&frame.speed)); } else { ESP_LOGD(tag, "$xxRMC sentence is not parsed\n"); } break; case MINMEA_SENTENCE_GGA: //ESP_LOGD(tag, "Sentence - MINMEA_SENTENCE_GGA"); break; case MINMEA_SENTENCE_GSV: //ESP_LOGD(tag, "Sentence - MINMEA_SENTENCE_GSV"); break; default: //ESP_LOGD(tag, "Sentence - other"); break; } } } // doGPS
// FreeRTOS task to start Mongoose. static void mongooseTask(void *data) { struct mg_mgr mgr; struct mg_connection *connection; ESP_LOGD(tag, ">> mongooseTask"); g_mongooseStopRequest = 0; // Unset the stop request since we are being asked to start. mg_mgr_init(&mgr, NULL); connection = mg_bind(&mgr, ":80", mongoose_event_handler); if (connection == NULL) { ESP_LOGE(tag, "No connection from the mg_bind()."); mg_mgr_free(&mgr); ESP_LOGD(tag, "<< mongooseTask"); vTaskDelete(NULL); return; } mg_set_protocol_http_websocket(connection); // Keep processing until we are flagged that there is a stop request. while (!g_mongooseStopRequest) { mg_mgr_poll(&mgr, 1000); } // We have received a stop request, so stop being a web server. mg_mgr_free(&mgr); g_mongooseStarted = 0; // Since we HAVE ended mongoose, time to invoke the callback. if (g_callback) { g_callback(1); } ESP_LOGD(tag, "<< mongooseTask"); vTaskDelete(NULL); return; } // mongooseTask
/** * @brief Dump the state of the buffer. * @return N/A */ void DMABuffer::dump() { std::ostringstream ss; ss << "size: " << m_desc.size; ss << ", buf: 0x" << std::hex << (uint32_t) m_desc.buf << std::dec; ss << ", length: " << m_desc.length; ss << ", offset: " << m_desc.offset; ss << ", sosf: " << m_desc.sosf; ss << ", eof: " << m_desc.eof; ss << ", owner: " << m_desc.owner; ESP_LOGD(LOG_TAG, "Desc: %s", ss.str().c_str()); int length = 100; if (length > m_desc.length) length = m_desc.length; GeneralUtils::hexDump((uint8_t*) m_desc.buf, length); }
/** * @brief Connect to the AWS IoT service. * Connect to the AWT IoT service. * @param [in] The client id. * @return N/A. */ void AWS::connect(std::string clientId) { IoT_Client_Connect_Params connectParams = iotClientConnectParamsDefault; connectParams.keepAliveIntervalInSec = 10; connectParams.isCleanSession = true; connectParams.MQTTVersion = MQTT_3_1_1; connectParams.isWillMsgPresent = false; connectParams.pClientID = clientId.c_str(); connectParams.clientIDLen = clientId.length(); IoT_Error_t err = ::aws_iot_mqtt_connect(&m_client, &connectParams); if (err != SUCCESS) { ESP_LOGD(tag, "aws_iot_mqtt_connect: error=%d", err); } } // connect