Commit 3b25b686 authored by omwansafelix's avatar omwansafelix

deleted Test Folder

parent 74552646
############################################################
# Dockerfile to build esp32 container
## Author: Alois Mbutura
## Modified by : Allan Juma
#run with docker run -t -i --device=/dev/ttyUSB0 ubuntu bash
#The script here is derived from: http://esp-idf.readthedocs.io/en/latest/linux-setup.html
############################################################
# Set the base image to Ubuntu
FROM ubuntu:16.04
# File Author / Maintainer
MAINTAINER [email protected]
# Update the repository sources list
RUN apt-get update
################## BEGIN INSTALLATION ######################
RUN BASE=$(pwd)
RUN apt-get update && apt-get install -y git make libncurses-dev flex bison gperf python python-serial wget --fix-missing
# Get or update IDF
RUN echo "[$0]: Get or update IDF"
RUN if [ -d esp-idf ]; then echo "[$0]: Found esp-idf, updating." && cd esp-idf && git pull && git submodule update --recursive && cd $BASE; else git clone --recursive https://github.com/espressif/esp-idf.git; fi
## Perform mandatory removal of any tar files in case of a previous error
RUN if [ -f *.tar.gz ] || [ -f *.tar.gz.* ]; then echo "[$0]: Removing residual tar file(s)" && rm *.tar.gz 2>/dev/null && rm *.tar.gz.* 2>/dev/null; fi
## Get 64 bit linux binary toolchain -- this might get out of date when they change blobs:
## Current version 1.22.0-61-gab8375a-5.2.0
RUN if [ -d xtensa-esp32-elf ]; then echo "[$0]: Found ESP32 binary toolchain. Performing mandatory replacement." && echo "[$0]: Current version at the making of this makefile 1.22.0-61-gab8375a-5.2.0" && echo "[$0]: Check current version from http://esp-idf.readthedocs.io/en/latest/linux-setup.html" && rm -rf xtensa-esp32-elf && wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz && tar -xvzf xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz; else wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz && tar -xvzf xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz && rm *.tar.gz; fi
## Get demo application
RUN echo "[$0]: Get demo application" && if [ -d esp-idf-template ]; then echo "[$0]: Found esp-idf-template, updating." && cd esp-idf-template && git pull && cd $BASE; else git clone https://github.com/espressif/esp-idf-template.git; fi
## Setup environment variables:
## Works for _this_ directory structure. You will need to change these if you deviate
## Also, you might copy these lines into a separate script to reset these variables as necessary.
RUN echo "[$0]: Setup environment variables"
ENV IDF_PATH ${BASE}/esp-idf
RUN echo "[$0]: export IDF_PATH=${BASE}/esp-idf"
ENV PATH "$PATH:${BASE}/xtensa-esp32-elf/bin"
RUN echo "[$0]: export PATH=$PATH:${BASE}/xtensa-esp32-elf/bin"
RUN echo ""
RUN echo "[$0]: IDF demo instructions"
RUN echo "[$0]: [1] cd $BASE/esp-idf-template and"
RUN echo "[$0]: [2] Type make menuconfig or make flash to get started"
# ESP32
## References
http://esp32.net/
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.1735130190">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.1735130190" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration buildProperties="" description="" id="0.1735130190" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.1735130190." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.499013179" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.499013179.1311733448" name=""/>
<builder id="org.eclipse.cdt.build.core.settings.default.builder.178068299" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.1058065446" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.918562185" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1903247773" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.2060320207" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.2067856277" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.165300558" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.470929854" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/esp32_ble_app_eddystone/build/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/esp32/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/freertos/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/log/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/mbedtls/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/nvs_flash/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/driver/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/spi_flash/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/esp32&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/bt/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/../xtensa-esp32-elf/xtensa-esp32-elf/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/../xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/4.8.5/include&quot;"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1133209003" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="esp32_ble_app_eddystone.null.385502392" name="esp32_ble_app_eddystone"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.420910566">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.1934615503">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.1735130190">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="flash" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>flash</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>05_ble_adv</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := ble_eddystone
COMPONENT_ADD_INCLUDEDIRS := components/include
include $(IDF_PATH)/make/project.mk
BLE Eddystone demo
===========================
This is a BLE advertising demo with virtual HCI interface. Send Reset/ADV_PARAM/ADV_DATA/ADV_ENABLE HCI command for BLE advertising.
esp-idf used
commit 1e0710f1b24429a316c9c34732aa17bd3f189421
Date: Fri May 12 18:23:20 2017 +0800
eclipse
include include.xml to C and C++ Paths
INSTALL
make menuconfig
(make clean)
make -j8 all
make flash
make monitor
<?xml version="1.0" encoding="UTF-8"?>
<cdtprojectproperties>
<section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.IncludePaths">
<language name="holder for library settings">
</language>
<language name="Assembly">
</language>
<language name="GNU C++">
</language>
<language name="GNU C">
<includepath workspace_path="true">/ble_app_eddystone/build/include</includepath>
<includepath>${IDF_PATH}/components/esp32/include</includepath>
<includepath>${IDF_PATH}/components/freertos/include</includepath>
<includepath>${IDF_PATH}/components/log/include</includepath>
<includepath>${IDF_PATH}/components/mbedtls/include</includepath>
<includepath>${IDF_PATH}/components/nvs_flash/include</includepath>
<includepath>${IDF_PATH}/components/driver/include</includepath>
<includepath>${IDF_PATH}/components/spi_flash/include</includepath>
<includepath>${IDF_PATH}/components/lwip/include/lwip/</includepath>
<includepath>${IDF_PATH}/components/esp32</includepath>
<includepath>${IDF_PATH}/components/bt/include</includepath>
<includepath>${IDF_PATH}/components/bt/bluedroid/include</includepath>
<includepath>${IDF_PATH}/components/bt/bluedroid/device/include</includepath>
<includepath>${IDF_PATH}/components/bt/bluedroid/stack/include</includepath>
<includepath>${IDF_PATH}/components/bt/bluedroid/bta/include</includepath>
<includepath>${IDF_PATH}/components/bt/bluedroid/api/include</includepath>
<includepath>${IDF_PATH}/../xtensa-esp32-elf/xtensa-esp32-elf/include</includepath>
<includepath>${IDF_PATH}/../xtensa-esp32-elf/lib/gcc/xtensa-esp32-elf/5.2.0/include</includepath>
<includepath>${IDF_PATH}/components/micro-ecc/micro-ecc</includepath>
</language>
</section>
<section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.Macros">
<language name="holder for library settings">
</language>
<language name="Assembly">
</language>
<language name="GNU C++">
</language>
<language name="GNU C">
</language>
</section>
</cdtprojectproperties>
#include <stdio.h>
#include <string.h>
#include "stdbool.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#include "bt.h"
#define GATTS_TAG "MAIN"
#define HCI_H4_CMD_PREAMBLE_SIZE (4)
/* HCI Command opcode group field(OGF) */
#define HCI_GRP_HOST_CONT_BASEBAND_CMDS (0x03 << 10) /* 0x0C00 */
#define HCI_GRP_BLE_CMDS (0x08 << 10)
#define HCI_RESET (0x0003 | HCI_GRP_HOST_CONT_BASEBAND_CMDS)
#define HCI_BLE_WRITE_ADV_ENABLE (0x000A | HCI_GRP_BLE_CMDS)
#define HCI_BLE_WRITE_ADV_PARAMS (0x0006 | HCI_GRP_BLE_CMDS)
#define HCI_BLE_WRITE_ADV_DATA (0x0008 | HCI_GRP_BLE_CMDS)
#define HCIC_PARAM_SIZE_WRITE_ADV_ENABLE (1)
#define HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS (15)
#define HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA (31)
#define BD_ADDR_LEN (6) /* Device address length */
typedef uint8_t bd_addr_t[BD_ADDR_LEN]; /* Device address */
#define UINT16_TO_STREAM(p, u16) {*(p)++ = (uint8_t)(u16); *(p)++ = (uint8_t)((u16) >> 8);}
#define UINT8_TO_STREAM(p, u8) {*(p)++ = (uint8_t)(u8);}
#define BDADDR_TO_STREAM(p, a) {int ijk; for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *(p)++ = (uint8_t) a[BD_ADDR_LEN - 1 - ijk];}
#define ARRAY_TO_STREAM(p, a, len) {int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (uint8_t) a[ijk];}
enum {
H4_TYPE_COMMAND = 1,
H4_TYPE_ACL = 2,
H4_TYPE_SCO = 3,
H4_TYPE_EVENT = 4
};
static uint8_t hci_cmd_buf[128];
/*
* @brief: BT controller callback function, used to notify the upper layer that
* controller is ready to receive command
*/
static void controller_rcv_pkt_ready(void)
{
printf("controller rcv pkt ready\n");
}
/*
* @brief: BT controller callback function, to transfer data packet to upper
* controller is ready to receive command
*/
static int host_rcv_pkt(uint8_t *data, uint16_t len)
{
printf("host rcv pkt: ");
for (uint16_t i=0; i<len; i++)
printf("%02x", data[i]);
printf("\n");
return 0;
}
static esp_vhci_host_callback_t vhci_host_cb = {
controller_rcv_pkt_ready,
host_rcv_pkt
};
static uint16_t make_cmd_reset(uint8_t *buf)
{
UINT8_TO_STREAM (buf, H4_TYPE_COMMAND);
UINT16_TO_STREAM (buf, HCI_RESET);
UINT8_TO_STREAM (buf, 0);
return HCI_H4_CMD_PREAMBLE_SIZE;
}
static uint16_t make_cmd_ble_set_adv_enable (uint8_t *buf, uint8_t adv_enable)
{
UINT8_TO_STREAM (buf, H4_TYPE_COMMAND);
UINT16_TO_STREAM (buf, HCI_BLE_WRITE_ADV_ENABLE);
UINT8_TO_STREAM (buf, HCIC_PARAM_SIZE_WRITE_ADV_ENABLE);
UINT8_TO_STREAM (buf, adv_enable);
return HCI_H4_CMD_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_ADV_ENABLE;
}
static uint16_t make_cmd_ble_set_adv_param (uint8_t *buf, uint16_t adv_int_min, uint16_t adv_int_max,
uint8_t adv_type, uint8_t addr_type_own,
uint8_t addr_type_dir, bd_addr_t direct_bda,
uint8_t channel_map, uint8_t adv_filter_policy)
{
UINT8_TO_STREAM (buf, H4_TYPE_COMMAND);
UINT16_TO_STREAM (buf, HCI_BLE_WRITE_ADV_PARAMS);
UINT8_TO_STREAM (buf, HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS );
UINT16_TO_STREAM (buf, adv_int_min);
UINT16_TO_STREAM (buf, adv_int_max);
UINT8_TO_STREAM (buf, adv_type);
UINT8_TO_STREAM (buf, addr_type_own);
UINT8_TO_STREAM (buf, addr_type_dir);
BDADDR_TO_STREAM (buf, direct_bda);
UINT8_TO_STREAM (buf, channel_map);
UINT8_TO_STREAM (buf, adv_filter_policy);
return HCI_H4_CMD_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS;
}
static uint16_t make_cmd_ble_set_adv_data(uint8_t *buf, uint8_t data_len, uint8_t *p_data)
{
UINT8_TO_STREAM (buf, H4_TYPE_COMMAND);
UINT16_TO_STREAM (buf, HCI_BLE_WRITE_ADV_DATA);
UINT8_TO_STREAM (buf, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1);
memset(buf, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA);
if (p_data != NULL && data_len > 0) {
if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA) {
data_len = HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA;
}
UINT8_TO_STREAM (buf, data_len);
ARRAY_TO_STREAM (buf, p_data, data_len);
}
return HCI_H4_CMD_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1;
}
static void hci_cmd_send_reset(void)
{
uint16_t sz = make_cmd_reset (hci_cmd_buf);
esp_vhci_host_send_packet(hci_cmd_buf, sz);
}
static void hci_cmd_send_ble_adv_start(void)
{
uint16_t sz = make_cmd_ble_set_adv_enable (hci_cmd_buf, 1);
esp_vhci_host_send_packet(hci_cmd_buf, sz);
}
static void hci_cmd_send_ble_set_adv_param(void)
{
uint16_t adv_intv_min = 256; // 160ms
uint16_t adv_intv_max = 256; // 160ms
uint8_t adv_type = 0; // connectable undirected advertising (ADV_IND)
uint8_t own_addr_type = 0; // Public Device Address
uint8_t peer_addr_type = 0; // Public Device Address
uint8_t peer_addr[6] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85};
uint8_t adv_chn_map = 0x07; // 37, 38, 39
uint8_t adv_filter_policy = 0; // Process All Conn and Scan
uint16_t sz = make_cmd_ble_set_adv_param(hci_cmd_buf,
adv_intv_min,
adv_intv_max,
adv_type,
own_addr_type,
peer_addr_type,
peer_addr,
adv_chn_map,
adv_filter_policy);
esp_vhci_host_send_packet(hci_cmd_buf, sz);
}
static void hci_cmd_send_ble_set_adv_data(void)
{
uint8_t adv_data[31];
uint8_t adv_data_len;
adv_data[0] = 2; // Len
adv_data[1] = 0x01; // Type Flags
adv_data[2] = 0x06; // GENERAL_DISC_MODE 0x02 | BR_EDR_NOT_SUPPORTED 0x04
adv_data[3] = 3; // Len
adv_data[4] = 0x03; // Type 16-Bit UUID
adv_data[5] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB
adv_data[6] = 0xFE; // Eddystone UUID 1 MSB
adv_data[7] = 21; // Length of Beacon Data
adv_data[8] = 0x16; // Type Service Data
adv_data[9] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB
adv_data[10] = 0xFE; // Eddystone UUID 1 MSB
adv_data[11] = 0x10; // Eddystone Frame Type
adv_data[12] = 0x20; // Beacons TX power at 0m
adv_data[13] = 0x03; // URL Scheme 'https://'
adv_data[14] = 0x62; // URL add 1 'b'
adv_data[15] = 0x69; // URL add 2 'i'
adv_data[16] = 0x74; // URL add 3 't'
adv_data[17] = 0x73; // URL add 4 's'
adv_data[18] = 0x6F; // URL add 5 'o'
adv_data[19] = 0x6B; // URL add 6 'k'
adv_data[20] = 0x6F; // URL add 7 'o'
adv_data[21] = 0x2E; // URL add 8 '.'
adv_data[22] = 0x69; // URL add 9 'i'
adv_data[23] = 0x6F; // URL add 10 'o'
adv_data[24] = 0x2F; // URL add 11 '/'
adv_data[25] = 0x70; // URL add 12 'p'
adv_data[26] = 0x66; // URL add 14 'f'
adv_data[27] = 0x30; // URL add 15 '0'
adv_data[28] = 0x64; // URL add 16 'd'
adv_data_len = 29;
printf("Eddystone adv_data [%d]=",adv_data_len);
for (int i=0; i<adv_data_len; i++) {
printf("%02x",adv_data[i]);
}
printf("\n");
uint16_t sz = make_cmd_ble_set_adv_data(hci_cmd_buf, adv_data_len, (uint8_t *)adv_data);
esp_vhci_host_send_packet(hci_cmd_buf, sz);
}
/*
* @brief: send HCI commands to perform BLE advertising;
*/
void bleAdvtTask(void *pvParameters)
{
int cmd_cnt = 0;
bool send_avail = false;
esp_vhci_host_register_callback(&vhci_host_cb);
printf("BLE advt task start\n");
while (1) {
vTaskDelay(5000 / portTICK_PERIOD_MS);
send_avail = esp_vhci_host_check_send_available();
if (send_avail) {
switch (cmd_cnt) {
case 0: hci_cmd_send_reset(); ++cmd_cnt; break;
case 1: hci_cmd_send_ble_set_adv_param(); ++cmd_cnt; break;
case 2: hci_cmd_send_ble_set_adv_data(); ++cmd_cnt; break;
case 3: hci_cmd_send_ble_adv_start(); ++cmd_cnt; break;
}
}
printf("BLE Advertise, flag_send_avail: %d, cmd_sent: %d\n", send_avail, cmd_cnt);
}
}
int app_main() {
esp_err_t ret;
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
ESP_LOGE(GATTS_TAG, "%s initialize controller failed\n", __func__);
return 1;
}
ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
if (ret) {
ESP_LOGE(GATTS_TAG, "%s enable controller failed\n", __func__);
return 1;
}
xTaskCreatePinnedToCore(&bleAdvtTask, "bleAdvtTask", 2048, NULL, 5, NULL, 0);
return 0;
}
#
# Main Makefile. This is basically the same as a component makefile.
#
# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default,
# this will take the sources in the src/ directory, compile them and link them into
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
# please read the ESP-IDF documents if you need to do this.
#
#
# Automatically generated file; DO NOT EDIT.
# Espressif IoT Development Framework Configuration
#
#
# SDK tool configuration
#
CONFIG_TOOLPREFIX="xtensa-esp32-elf-"
CONFIG_PYTHON="python"
#
# Bootloader config
#
# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set
# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set
# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set
CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set
# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set
CONFIG_LOG_BOOTLOADER_LEVEL=3
#
# Security features
#
# CONFIG_SECURE_BOOT_ENABLED is not set
# CONFIG_FLASH_ENCRYPTION_ENABLED is not set
#
# Serial flasher config
#
CONFIG_ESPTOOLPY_PORT="/dev/ttyUSB0"
# CONFIG_ESPTOOLPY_BAUD_115200B is not set
# CONFIG_ESPTOOLPY_BAUD_230400B is not set
# CONFIG_ESPTOOLPY_BAUD_921600B is not set
# CONFIG_ESPTOOLPY_BAUD_2MB is not set
CONFIG_ESPTOOLPY_BAUD_OTHER=y
CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=1500000
CONFIG_ESPTOOLPY_BAUD=1500000
CONFIG_ESPTOOLPY_COMPRESSED=y
# CONFIG_FLASHMODE_QIO is not set
# CONFIG_FLASHMODE_QOUT is not set
CONFIG_FLASHMODE_DIO=y
# CONFIG_FLASHMODE_DOUT is not set
CONFIG_ESPTOOLPY_FLASHMODE="dio"
# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set
CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
CONFIG_ESPTOOLPY_FLASHFREQ="40m"
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE="2MB"
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
CONFIG_ESPTOOLPY_BEFORE_RESET=y
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set
CONFIG_ESPTOOLPY_BEFORE="default_reset"
CONFIG_ESPTOOLPY_AFTER_RESET=y
# CONFIG_ESPTOOLPY_AFTER_NORESET is not set
CONFIG_ESPTOOLPY_AFTER="hard_reset"
# CONFIG_MONITOR_BAUD_9600B is not set
# CONFIG_MONITOR_BAUD_57600B is not set
CONFIG_MONITOR_BAUD_115200B=y
# CONFIG_MONITOR_BAUD_230400B is not set
# CONFIG_MONITOR_BAUD_921600B is not set
# CONFIG_MONITOR_BAUD_2MB is not set
# CONFIG_MONITOR_BAUD_OTHER is not set
CONFIG_MONITOR_BAUD_OTHER_VAL=115200
CONFIG_MONITOR_BAUD=115200
#
# Partition Table
#
CONFIG_PARTITION_TABLE_SINGLE_APP=y
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
# CONFIG_PARTITION_TABLE_CUSTOM is not set
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv"
CONFIG_APP_OFFSET=0x10000
CONFIG_OPTIMIZATION_LEVEL_DEBUG=y
# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set
#
# Component config
#
# CONFIG_AWS_IOT_SDK is not set
CONFIG_BT_ENABLED=y
CONFIG_BLUEDROID_ENABLED=y
CONFIG_BTC_TASK_STACK_SIZE=3072
# CONFIG_BLUEDROID_MEM_DEBUG is not set
# CONFIG_CLASSIC_BT_ENABLED is not set
# CONFIG_BT_DRAM_RELEASE is not set
CONFIG_GATTS_ENABLE=y
CONFIG_GATTC_ENABLE=y
CONFIG_SMP_ENABLE=y
# CONFIG_BT_STACK_NO_LOG is not set
CONFIG_BT_ACL_CONNECTIONS=4
CONFIG_BTDM_CONTROLLER_RUN_CPU=0
CONFIG_BT_RESERVE_DRAM=0x10000
#
# ESP32-specific
#
# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set
# CONFIG_ESP32_DEFAULT_CPU_FREQ_160 is not set
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240
CONFIG_MEMMAP_SMP=y
# CONFIG_MEMMAP_TRACEMEM is not set
# CONFIG_MEMMAP_TRACEMEM_TWOBANKS is not set
# CONFIG_ESP32_TRAX is not set
CONFIG_TRACEMEM_RESERVE_DRAM=0x0
# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set
# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y
# CONFIG_ESP32_ENABLE_COREDUMP is not set
# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set
# CONFIG_ESP32_APPTRACE_DEST_UART is not set
CONFIG_ESP32_APPTRACE_DEST_NONE=y
# CONFIG_ESP32_APPTRACE_ENABLE is not set
# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set
CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=4096
CONFIG_MAIN_TASK_STACK_SIZE=4096
CONFIG_NEWLIB_STDOUT_ADDCR=y
# CONFIG_NEWLIB_NANO_FORMAT is not set
CONFIG_CONSOLE_UART_DEFAULT=y
# CONFIG_CONSOLE_UART_CUSTOM is not set
# CONFIG_CONSOLE_UART_NONE is not set
CONFIG_CONSOLE_UART_NUM=0
CONFIG_CONSOLE_UART_BAUDRATE=115200
# CONFIG_ULP_COPROC_ENABLED is not set
CONFIG_ULP_COPROC_RESERVE_MEM=0
# CONFIG_ESP32_PANIC_PRINT_HALT is not set
CONFIG_ESP32_PANIC_PRINT_REBOOT=y
# CONFIG_ESP32_PANIC_SILENT_REBOOT is not set
# CONFIG_ESP32_PANIC_GDBSTUB is not set
CONFIG_ESP32_DEBUG_OCDAWARE=y
CONFIG_INT_WDT=y
CONFIG_INT_WDT_TIMEOUT_MS=300
CONFIG_INT_WDT_CHECK_CPU1=y
CONFIG_TASK_WDT=y
# CONFIG_TASK_WDT_PANIC is not set
CONFIG_TASK_WDT_TIMEOUT_S=5
CONFIG_TASK_WDT_CHECK_IDLE_TASK=y
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=y
# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set
CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y
# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set
# CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set
CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set
CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024
CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=0
# CONFIG_ESP32_XTAL_FREQ_40 is not set
# CONFIG_ESP32_XTAL_FREQ_26 is not set
CONFIG_ESP32_XTAL_FREQ_AUTO=y
CONFIG_ESP32_XTAL_FREQ=0
# CONFIG_WIFI_ENABLED is not set
CONFIG_PHY_ENABLED=y
#
# PHY
#
CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y
# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set
CONFIG_ESP32_PHY_MAX_TX_POWER=20
# CONFIG_ETHERNET is not set
#
# FAT Filesystem support
#
CONFIG_FATFS_CODEPAGE_ASCII=y
# CONFIG_FATFS_CODEPAGE_437 is not set
# CONFIG_FATFS_CODEPAGE_720 is not set
# CONFIG_FATFS_CODEPAGE_737 is not set
# CONFIG_FATFS_CODEPAGE_771 is not set
# CONFIG_FATFS_CODEPAGE_775 is not set
# CONFIG_FATFS_CODEPAGE_850 is not set
# CONFIG_FATFS_CODEPAGE_852 is not set
# CONFIG_FATFS_CODEPAGE_855 is not set
# CONFIG_FATFS_CODEPAGE_857 is not set
# CONFIG_FATFS_CODEPAGE_860 is not set
# CONFIG_FATFS_CODEPAGE_861 is not set
# CONFIG_FATFS_CODEPAGE_862 is not set
# CONFIG_FATFS_CODEPAGE_863 is not set
# CONFIG_FATFS_CODEPAGE_864 is not set
# CONFIG_FATFS_CODEPAGE_865 is not set
# CONFIG_FATFS_CODEPAGE_866 is not set
# CONFIG_FATFS_CODEPAGE_869 is not set
# CONFIG_FATFS_CODEPAGE_932 is not set
# CONFIG_FATFS_CODEPAGE_936 is not set
# CONFIG_FATFS_CODEPAGE_949 is not set
# CONFIG_FATFS_CODEPAGE_950 is not set
CONFIG_FATFS_CODEPAGE=1
CONFIG_FATFS_MAX_LFN=255
#
# FreeRTOS
#
# CONFIG_FREERTOS_UNICORE is not set
CONFIG_FREERTOS_CORETIMER_0=y
# CONFIG_FREERTOS_CORETIMER_1 is not set
CONFIG_FREERTOS_HZ=100
CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1
CONFIG_FREERTOS_ASSERT_FAIL_ABORT=y
# CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE is not set
# CONFIG_FREERTOS_ASSERT_DISABLE is not set
CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG=y
# CONFIG_ENABLE_MEMORY_DEBUG is not set
CONFIG_FREERTOS_ISR_STACKSIZE=1536
# CONFIG_FREERTOS_LEGACY_HOOKS is not set
CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16
# CONFIG_SUPPORT_STATIC_ALLOCATION is not set
CONFIG_TIMER_TASK_PRIORITY=1
CONFIG_TIMER_TASK_STACK_DEPTH=2048
CONFIG_TIMER_QUEUE_LENGTH=10
# CONFIG_FREERTOS_DEBUG_INTERNALS is not set
#
# Log output
#
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set
# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_COLORS=y
#
# LWIP
#
# CONFIG_L2_TO_L3_COPY is not set
CONFIG_LWIP_MAX_SOCKETS=10
CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX=0
# CONFIG_LWIP_SO_REUSE is not set
# CONFIG_LWIP_SO_RCVBUF is not set
CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1
# CONFIG_LWIP_IP_FRAG is not set
# CONFIG_LWIP_IP_REASSEMBLY is not set
CONFIG_TCP_MAXRTX=12
CONFIG_TCP_SYNMAXRTX=6
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
CONFIG_TCPIP_TASK_STACK_SIZE=2560
# CONFIG_PPP_SUPPORT is not set
#
# mbedTLS
#
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384
# CONFIG_MBEDTLS_DEBUG is not set
CONFIG_MBEDTLS_HARDWARE_AES=y
CONFIG_MBEDTLS_HARDWARE_MPI=y
CONFIG_MBEDTLS_MPI_USE_INTERRUPT=y
CONFIG_MBEDTLS_HARDWARE_SHA=y
CONFIG_MBEDTLS_HAVE_TIME=y
# CONFIG_MBEDTLS_HAVE_TIME_DATE is not set
#
# OpenSSL
#
# CONFIG_OPENSSL_DEBUG is not set
CONFIG_OPENSSL_ASSERT_DO_NOTHING=y
# CONFIG_OPENSSL_ASSERT_EXIT is not set
#
# SPI Flash driver
#
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
## Author: Felix Omwansa
echo ""
echo "[$0]: This file should be run in the directory where the project is located.
Paste and run it in the directory, although this is done automatically from buildESP32.sh"
##Allow read and write access to USB device
echo ""
echo "[$0]: Setup access to USB device"
sudo chmod a+rw /dev/ttyUSB0
##configure project
echo ""
echo "[$0]: Run configuration menu"
make menuconfig
##erase and flash current project to ESP and run serial monitor to view results
echo ""
echo "[$0]: Erase everything on device then flash the current project"
make erase_flash flash monitor
## Author: Elliot Williams
## Modified by : Alois Mbutura and Felix Omwansa
echo ""
echo "[$0]: Bitsoko ESP32 script initialized"
##FUNCTION: build development framework
build_framework() {
echo "FUNCTION: build_framework"
echo "[$0]: This will build the development framework for the ESP32, set the required path variables and move the resource folders into the project folder."
## Install the esp-idf and set required variables
## BASE variable-This is where you want the entire toolchain to live
#The script here is derived from: http://esp-idf.readthedocs.io/en/latest/linux-setup.html
BASE=$(pwd)
echo ""
echo "[$0]: Checking for system prerequisites."
#Archlinux
if [ $(which pacman) ]
then
echo "[$0]: Found archlinux based system."
sudo pacman -S --needed gcc git make ncurses flex bison gperf python2-pyserial wget 2>/dev/null
fi
#Ubuntu
if [ $(which apt-get) ]
then
echo "[$0]: Found Ubuntu based system."
sudo apt-get update
sudo apt-get install git make libncurses-dev flex bison gperf python python-serial wget 2>/dev/null
fi
#Any other system goes here
# Get or update IDF
echo ""
echo "[$0]: Get or update IDF"
if [ -d esp-idf ]
then
echo "[$0]: Found esp-idf, updating."
cd esp-idf
git pull && git submodule update --recursive
cd $BASE
else ## not found, get it
git clone --recursive https://github.com/espressif/esp-idf.git
fi
## Perform mandatory removal of any tar files in case of a previous error
if [ -f *.tar.gz ] || [ -f *.tar.gz.* ]
then
echo ""
echo "[$0]: Removing residual tar file(s)"
rm *.tar.gz 2>/dev/null
rm *.tar.gz.* 2>/dev/null
fi
## Get 64 bit linux binary toolchain -- this might get out of date when they change blobs:
## Current version 1.22.0-61-gab8375a-5.2.0
echo ""
echo "[$0]: Get 64 bit linux binary toolchain -- this might get out of date when they change blobs"
if [ -d xtensa-esp32-elf ]
then
echo "[$0]: Found ESP32 binary toolchain. Performing mandatory replacement."
echo "[$0]: Current version at the making of this makefile 1.22.0-61-gab8375a-5.2.0"
echo "[$0]: Check current version from http://esp-idf.readthedocs.io/en/latest/linux-setup.html"
rm -rf xtensa-esp32-elf
wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
tar -xvzf xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
# rm *.tar.gz 2>/dev/null && rm *.tar.gz.* 2>/dev/null
else
wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
tar -xvzf xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
rm *.tar.gz 2>/dev/null && rm *.tar.gz.* 2>/dev/null
fi
## Setup environment variables:
echo ""
echo "[$0]: Setup environment variables"
echo "[$0]: Exporting environment variables:"
export IDF_PATH=${BASE}/esp-idf
echo "[$0]: export IDF_PATH=${BASE}/esp-idf"
export PATH=$PATH:${BASE}/xtensa-esp32-elf/bin
echo "[$0]: export PATH=$PATH:${BASE}/xtensa-esp32-elf/bin"
##move the project folders to narra directory:
mkdir narra
##eddystone
mv ble_app_eddystone narra
##nodejs
mkdir esp32-nodejs-app
mv package.json esp32-nodejs-app
mv install_noble.sh esp32-nodejs-app
mv listen-notification.js esp32-nodejs-app
mv listenNode.sh gatt_server_notif_switch
mv gatt_server_notif_switch esp32-nodejs-app
mv esp32-nodejs-app narra
echo "[$0]: BUILD SUCCESSFUL"
echo ""
pwd
echo ""
ls
echo ""
##read user action after completing building the framework
custom_app_instructions
read action
##eddystone
if [ $action = build_eddystone_app ]
then
build_eddystone_app
#nodejs_app
elif [ $action = build_nodejs_app ]
then
build_nodejs_app
#quit
elif [ $action = quit ]
then
echo ""
echo "[$0]: Bitsoko ESP32 script terminated"
echo ""
fi
}
##end of function
#FUNCTION: compile and flash custom app to the ESP32
build_app(){
echo ""
echo "[$0]: This compiles and flashes the project into the ESP32."
echo "[$0]: NOTE: You should run this function from the working directory."
#compiling and flashing project binaries
##Allow read and write access to USB device
echo ""
echo "[$0]: Setup access to USB device... "
sudo chmod a+rw /dev/ttyUSB0
##configure project
echo ""
echo "[$0]: Run configuration menu..."
make menuconfig
##erase and flash current project to ESP and run serial monitor to view results
echo ""
echo "[$0]: Erase everything on device then flash the current project"
make erase_flash flash
echo "[$0]: BUILD SUCCESSFUL"
echo ""
pwd
echo ""
ls
echo ""
}
##end of function
##FUNCTIONS: building custom apps
build_eddystone_app(){
##run path_config to set up environment variables
. path_config.sh
cd narra/ble_app_eddystone
echo ""
pwd
echo ""
ls
echo ""
build_app
make monitor
}
build_nodejs_app(){
##run path_config to set up environment variables
. path_config.sh
echo ""
pwd
echo ""
ls
echo ""
echo ""
echo "APP BUILD INSTRUCTIONS"
echo ""
echo "[$0]: Run 'listenNode.sh' in the terminal that opens AFTER this app has been built successfully. This script will open a serial monitor to show the notification dialog box that detects action on the ESP."
cd narra/esp32-nodejs-app/gatt_server_notif_switch
build_app
##open separate terminal to run "listenNode.sh"
echo ""
echo "[$0]: Run 'listenNode.sh' in the terminal that opens AFTER this app has been built successfully. This script will open a serial monitor to show the notification dialog box that detects action on the ESP."
gnome-terminal
make monitor
}
##any other build function goes here
####################################
#Build instructions
custom_app_instructions(){
echo ""
echo "[$0]: 2. Run 'build_eddystone_app' to compile and flash the eddystone project to the ESP32."
echo ""
echo "[$0]: 3. Run 'build_nodejs_app' to compile and flash the nodejs_app project to the ESP32."
echo ""
echo "[$0]: 4. Run 'quit' to quit."
echo ""
}
echo ""
echo "[$0]: PROJECT BUILD INSTRUCTIONS"
echo ""
echo "NOTE: All commands should be run from the current directory, and custom apps can only be build after the framework has been setup."
echo ""
echo "What would you like to do?"
echo ""
echo "[$0]: 1. Run 'build_framework' to setup the development framework for ESP32 in the working directory."
echo ""
echo "[$0]: 2. Run 'build_eddystone_app' to compile and flash the eddystone project to the ESP32."
echo ""
echo "[$0]: 3. Run 'build_nodejs_app' to compile and flash the nodejs_app project to the ESP32."
echo ""
echo "[$0]: 4. Run 'quit' to quit."
echo ""
read action
##framework
if [ $action = build_framework ]
then
build_framework
##eddystone
elif [ $action = build_eddystone_app ]
then
build_eddystone_app
#nodejs_app
elif [ $action = build_nodejs_app ]
then
build_nodejs_app
#quit
elif [ $action = quit ]
then
echo ""
echo "[$0]: Bitsoko ESP32 script terminated"
echo ""
fi
##############
Subproject commit a0048ac138a3a29330c7d935faa03dd6625a1b49
//Author: Felix Omwansa
/* fgets example */
// reading text from a file, converting it to hexadecimal ASCII equivalent, then printing output.
#include <stdio.h>
#include <string.h>
int main() {
FILE * pFile;
unsigned char testWord[10]; //strings will be stored in these arrays
unsigned char defaultIndexes[2]= {"0", "x"};
int i, j, k,l, m, n, len, len2; //looping operators
pFile = fopen ("urlData.txt" , "r");
if (pFile == NULL) perror ("Error opening file");
else {
if ( fgets (testWord , 100 , pFile) != NULL )
puts (testWord); //file data stored in testWord
//conversion to hex
len = strlen(testWord);
unsigned char mystring[len*2 + 1];
len2= strlen(mystring);
unsigned char hexOut[len2][4];
if (testWord[len-1]=='\n')
testWord[--len] = '\0';
for(i=0; i<len; i++){
//initialise msystring array
sprintf(mystring+i*2 , "%02X", testWord[i]);
hexOut[i][0]=defaultIndexes[0];
hexOut[i][1]=defaultIndexes[1];
// if (i==0)
// k=i;
// hexOut[k][2]=mystring[(k];
// hexOut[k][3]=mystring[k+1];
// k=k+1
} //end of for
//print output
printf("Raw hex data of ' %s ' is: \t %s \n", testWord, mystring);
//output each array element's value
for (m=0; m<len2; m++) {
for (n=0; n<4; n++){
printf("Multidimensional array output of hexOut at [%d][%d] = %d\n", m,n, hexOut[m][n] );
}
}
fclose (pFile);
} //end of else
return 0;
} //end of function main
//////
[
{
"id": 1,
"name": "46e",
"service": "3",
"account": 12,
"fullname": "46e3e4f0c3f8889d",
"owner": 66
}
]
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := gatt_server_demos
COMPONENT_ADD_INCLUDEDIRS := components/include
include $(IDF_PATH)/make/project.mk
# gatt_server_notif_switch
A sample program for ESP32 on esp-idf. This program send notification by push or release GPIO0 switch.
# Partner program
The following nodejs program can listen notice from this project.
- [esp32-nodejs-samples/listen-notification.js](https://github.com/asukiaaa/esp32-nodejs-samples/blob/master/listen-notification.js)
- [gatt_client_listen_notif_then_output_to_led](../gatt_client_listen_notif_then_output_to_led)
# License
Appache v2
# References
- [esp-idf/examples/bluetooth/gatt_server](https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/gatt_server)
- [esp-idf/examples/peripherals/gpio/](https://github.com/espressif/esp-idf/tree/master/examples/peripherals/gpio)
- [GATT SERVER API: esp_ble_gatts_send_indicate](http://esp-idf.readthedocs.io/en/latest/api/bluetooth/esp_gatts.html#_CPPv227esp_ble_gatts_send_indicate13esp_gatt_if_t8uint16_t8uint16_t8uint16_tP7uint8_tb)
- [ESP32からBLE GATTのnotifを発信し、nodejs(noble)で受信する方法](http://asukiaaa.blogspot.com/2017/04/esp32ble-gattnodejsnoble.html)
\ No newline at end of file
menu "Example 'GATT SERVER' Config"
config SET_RAW_ADV_DATA
bool "Use raw data for advertising packets and scan response data"
help
If this config item is set, raw binary data will be used to generate advertising & scan response data.
This option uses the esp_ble_gap_config_adv_data_raw() and esp_ble_gap_config_scan_rsp_data_raw() functions.
If this config item is unset, advertising & scan response data is provided via a higher-level esp_ble_adv_data_t structure.
The lower layer will generate the BLE packets. This option has higher overhead at runtime.
endmenu
#
# Main Makefile. This is basically the same as a component makefile.
#
# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default,
# this will take the sources in the src/ directory, compile them and link them into
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
# please read the ESP-IDF documents if you need to do this.
#
# Override some defaults so BT stack is enabled
# and WiFi disabled by default in this example
CONFIG_BT_ENABLED=y
CONFIG_WIFI_ENABLED=n
## Author: Elliot Williams
## Modified by : Alois Mbutura
## BASE variable-This is where you want the entire toolchain to live
## You should run this script from within the destination directory, or redefine the BASE variable to fit your lifestyle.
#The script here is derived from: http://esp-idf.readthedocs.io/en/latest/linux-setup.html
BASE=$(pwd)
echo ""
echo "[$0]: Checking for system prerequisites."
#Archlinux
if [ $(which pacman) ]
then
echo "[$0]: Found archlinux based system."
sudo pacman -S --needed gcc git make ncurses flex bison gperf python2-pyserial wget 2>/dev/null
fi
#Ubuntu
if [ $(which apt-get) ]
then
echo "[$0]: Found Ubuntu based system."
sudo apt-get update
sudo apt-get install git make libncurses-dev flex bison gperf python python-serial wget 2>/dev/null
fi
#Any other system goes here
# Get or update IDF
echo ""
echo "[$0]: Get or update IDF"
if [ -d esp-idf ]
then
echo "[$0]: Found esp-idf, updating."
cd esp-idf
git pull && git submodule update --recursive
cd $BASE
else ## not found, get it
git clone --recursive https://github.com/espressif/esp-idf.git
fi
## Perform mandatory removal of any tar files in case of a previous error
if [ -f *.tar.gz ] || [ -f *.tar.gz.* ]
then
echo ""
echo "[$0]: Removing residual tar file(s)"
rm *.tar.gz 2>/dev/null
rm *.tar.gz.* 2>/dev/null
fi
## Get 64 bit linux binary toolchain -- this might get out of date when they change blobs:
## Current version 1.22.0-61-gab8375a-5.2.0
echo ""
echo "[$0]: Get 64 bit linux binary toolchain -- this might get out of date when they change blobs"
if [ -d xtensa-esp32-elf ]
then
echo "[$0]: Found ESP32 binary toolchain. Performing mandatory replacement."
echo "[$0]: Current version at the making of this makefile 1.22.0-61-gab8375a-5.2.0"
echo "[$0]: Check current version from http://esp-idf.readthedocs.io/en/latest/linux-setup.html"
rm -rf xtensa-esp32-elf
wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
tar -xvzf xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
# rm *.tar.gz 2>/dev/null && rm *.tar.gz.* 2>/dev/null
else
wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
tar -xvzf xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
rm *.tar.gz 2>/dev/null && rm *.tar.gz.* 2>/dev/null
fi
## Get demo application
echo ""
echo "[$0]: Get demo application"
if [ -d esp-idf-template ]
then
echo "[$0]: Found esp-idf-template, updating."
cd esp-idf-template
git pull
cd $BASE
else ## not found, get it
git clone https://github.com/espressif/esp-idf-template.git
fi
## Setup environment variables:
## Works for _this_ directory structure. You will need to change these if you deviate
## Also, you might copy these lines into a separate script to reset these variables as necessary.
echo ""
echo "[$0]: Setup environment variables"
echo "[$0]: Exporting environment variables:"
export IDF_PATH=${BASE}/esp-idf
echo "[$0]: export IDF_PATH=${BASE}/esp-idf"
export PATH=$PATH:${BASE}/xtensa-esp32-elf/bin
echo "[$0]: export PATH=$PATH:${BASE}/xtensa-esp32-elf/bin"
echo ""
echo "[$0]: IDF demo instructions"
echo "[$0]: [1] cd $BASE/esp-idf-template and"
echo "[$0]: [2] Type make menuconfig or make flash to get started"
#Authors: Allan Juma and Felix Omwansa
##buildESP32_update: get data for broadcast_url from Bitsoko server
##Parsing a json response of a url to a file
##installing jq: a command-line JSON processor
echo ""
echo "[$0]: installing jq: a command-line JSON processor"
echo "[$0]: Checking for system prerequisites and installing the required toochain..."
sleep 3
echo ""
#Archlinux
if [ $(which pacman) ]
then
echo "[$0]: Found archlinux based system."
sudo pacman -Sy jq
fi
#Ubuntu
if [ $(which apt-get) ]
then
echo "[$0]: Found Ubuntu based system."
sudo apt-get update
sudo apt-get install jq
fi
#Any other system goes here
echo ""
echo "[$0]: getting json response from Bitsoko server..."
sleep 3
RESP=$(curl -s 'https://bitsoko.io/devices/?dID=46e3e4f0c3f8889d' 2>&1 )
echo ""
echo "[$0]: creating data file to store response..."
sleep 3
if [ -f urlData.txt ]
then
rm urlData.txt
fi
#directly pipe required url data to urlData.txt
echo "${RESP}" | jq -r '.[].name' >> urlData.txt
echo ""
echo "[$0]: finished"
sleep 3
####
## Author: Felix Omwansa
#This script installs noble : A Node.js BLE (Bluetooth Low Energy) central module.
echo ""
echo "[$0]: This script installs noble : A Node.js BLE (Bluetooth Low Energy) central module."
echo "[$0]: "
## If you already have Node installed, you might want to remove it. Some Node.js tools might execute Node.js as Node instead of Node.js, causing conflicts.
## Checking if node is on your system:
echo "[$0]: "
echo "[$0]: Checking if node is on your system... "
if which node > /dev/null
then
# add deb.nodesource repo commands
# install node
echo "[$0]: node is missing, installing node... "
echo "[$0]: "
## Install Node.js with Ubuntu Package Manager
sudo apt-get install nodejs
else
echo "[$0]: node is installed, skipping..."
echo ""
fi
##Then install the Node package manager, npm:
sudo apt-get install npm
## Installing Prerequisites: Ubuntu/Debian/Raspbian
echo "[$0]: Installing Prerequisites for Ubuntu/Debian/Raspbian system..."
echo ""
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
## Create a symbolic link for node, as many Node.js tools use this name to execute.
##perform check to verify
echo ""
echo "[$0]: perform check to verify if symbolic link file for node exists..."
if [ -f /usr/bin/node ]
then
echo "[$0]: /usr/bin/node exists, breaking operation..."
echo ""
else ## create symbolic link for node
sudo ln -s /usr/bin/nodejs /usr/bin/node
fi
## Install noble
echo "[$0]: Installating noble... "
echo ""
npm install noble
echo "[$0]: Installation complete. "
echo ""
##
## Author: Felix Omwansa
## If you already have Node installed, you might want to remove it. Some Node.js tools might execute Node.js as Node instead of Node.js, causing conflicts.
## Checking if node is on your system:
echo "[$0]: "
echo "[$0]: Checking if node is on your system: "
if which node > /dev/null
then
# add deb.nodesource repo commands
# install node
echo "[$0]: node is missing, installing node... "
echo "[$0]: "
## Install Node.js with Ubuntu Package Manager
sudo apt-get install nodejs
##Then install the Node package manager, npm:
sudo apt-get install npm
else
echo "[$0]: node is installed, skipping..."
fi
## If you found the old Node package installed, run this command to completely remove it:
## sudo apt-get remove --purge node
## Create a symbolic link for node, as many Node.js tools use this name to execute.
## this might be unnecessary if file exists
##perform check to verify
echo ""
echo "[$0]: perform check to verify if symbolic link file for node exists:"
if [ -f /usr/bin/node ]
then
echo "[$0]: /usr/bin/node exists, breaking operation..."
else ## create symbolic link for node
sudo ln -s /usr/bin/nodejs /usr/bin/node
fi
##Now both the Node and npm commands shoulde be working
'use strict'
const noble = require('noble')
noble.on('stateChange', state => {
console.log('state change', state)
if (state === 'poweredOn') {
noble.startScanning()
} else {
noble.stopScanning()
}
})
noble.on('discover', peri => {
noble.stopScanning()
const ad = peri.advertisement
console.log("ad name: ", ad.localName)
if (ad.localName == "ESP_GATTS_SWITCH") {
console.log("found target esp")
peri.connect(error => {
console.log("conected")
if (error) {
console.log("connection error:", error)
}
peri.discoverServices([], (error, services) => {
if (error) {
console.log("discover service error", error)
}
services.forEach(service => {
console.log("service uuid: ", service.uuid)
if (service.uuid == "ff") {
console.log("ff")
service.discoverCharacteristics([], (error, charas) => {
if (error) {
console.log("discover characteristics error", error)
}
charas.forEach(chara => {
console.log("found chara: ", chara.uuid)
if (chara.uuid == "ff01") {
chara.notify(true, (error) => {
if (error) {
console.log('listen notif error', error)
} else {
console.log('listen notif')
}
})
chara.on('data', (data, isNotif) => {
console.log('receoved notif', data, isNotif)
})
}
})
})
}
})
})
})
}
})
## Author: Felix Omwansa
##return to project directory
cd ..
#installs noble
echo ""
echo "[$0]: installing noble using install_noble.sh..."
. install_noble.sh
##run notification dialog
echo ""
echo "[$0]: This will open a notification dialog to detect action on the ESP32.sh"
echo ""
sudo node listen-notification.js
{
"name": "esp32-nodejs-samples",
"version": "1.0.0",
"description": "A node program to communicate with ESP32 on GATT",
"main": "write-and-listen.js",
"dependencies": {
"noble": "^1.8.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Asuki Kono",
"license": "ISC"
}
BASE=$(pwd)
echo "[$0]: Setup environment variables"
echo "[$0]: Exporting environment variables:"
export IDF_PATH=${BASE}/esp-idf
echo "[$0]: export IDF_PATH=${BASE}/esp-idf"
export PATH=$PATH:${BASE}/xtensa-esp32-elf/bin
echo "[$0]: export PATH=$PATH:${BASE}/xtensa-esp32-elf/bin"
#! /bin/sh
#Bitsoko script for intel edison
################################
clone(){
#Remove any folders and held contents recursively and non interactively.
echo "Removing stale folders..."
rm -rf ~/bitsoko ~/bitsoko_lite
echo "Making new directory"
mkdir ~/bitsoko_lite
cd ~/bitsoko_lite
echo "changing working directory, now cloning"
git clone https://github.com/bitsoko-services/hardware
echo "successfully setup bitsoko lite"
}
################################
install_deps(){
#Install sockets node lib ver 1.3.7
echo "Retreiving node prerequisites, kindly wait..."
npm install [email protected]
#Check for git and install if lacking
echo "Checking for git prerequisite, kindly wait..."
if [ -f /usr/bin/git ]
then
#Do nothing
else:
if [ opkg install git ]
then
#Do nothing
else
echo "src all http://iotdk.intel.com/repos/2.0/iotdk/all" >> /etc/opkg/base-feeds.conf
echo "src x86 http://iotdk.intel.com/repos/2.0/iotdk/x86" >> /etc/opkg/base-feeds.conf
echo "src i586 http://iotdk.intel.com/repos/2.0/iotdk/i586" >> /etc/opkg/base-feeds.conf
opkg update
opkg install git
fi
fi
}
################################
run_webpage(){
if [[ "$(ping -c 1 8.8.8.8 | grep '100% packet loss' )" != "" ]];
then
echo "Network absent"
exit 1
else
echo "Network is present"
echo "Available ip addresses on this computer"
ifconfig | awk '/inet addr/{print substr($2,6)}'
echo "Starting webserver demo"
node ~/bitsoko_lite/hardware/intel_edison/webpage.js
fi
}
################################
echo "Bitsoko lite script Initialized. what would you like to do? clone or quit or install_deps or run-webpage"
read action
if [ $action = clone ]
then
clone
exit
elif [ $action = install_deps ]
then
install_deps
exit
elif [ $action = quit ]
then
exit
elif [ $action = run-webpage ]
then
run_webpage
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment