U-BLOX NINA W106 SENDO PROGRAMADO Sming
O
objetivo deste BLOG é demonstrar como é possível utilizar programar o
módulo u-BLOX NINA W106 (ESP32) no starter kit EVK-NINA-W1 com o Framework Sming
Wi-Fi 802.11b/g/n
Dual-Mode Bluetooth v4.2
Poderoso suporte de CPU aberta para aplicativos personalizados
Tamanho pequeno e várias opções de antena
Pino compatível com outros módulos NINA
Certificação global
Módulo baseado no ESP32, com 4MB FLASH
SMARTCORE
A SmartCore fornece módulos para comunicação wireless, biometria, conectividade, rastreamento e automação.
Nosso
portifólio inclui modem 2G/3G/4G/NB-IoT/Cat.M, satelital, módulos WiFi,
Bluetooth, GNSS/GPS, Sigfox, LoRa, leitor de cartão, leitor QR code,
mecanismo de impressão, mini-board PC, antena, pigtail, LCD, bateria,
repetidor GPS e sensores.
Mais detalhes em www.smartcore.com.br
Sming
Características
Excelente desempenho e uso da memória (Sming compila para firmware nativo!).
Desenvolvimento rápido e amigável.
Invólucros de API de hardware simples, mas poderosos.
Compatível com bibliotecas Arduino padrão - use qualquer hardware popular em poucas linhas de código.
Sistema de arquivos embutido: spiffs.
Módulos sem fio poderosos embutidos.
Poderosa pilha de rede assíncrona.
-Pilha Async TCP e UDP baseada em LWIP.
-Com suporte a clientes: HTTP, MQTT, WebSockets e SMTP.
-E servidores para: DNS, FTP, HTTP(+ WebSockets), Telnet.
-Com suporte SSL para todos os clientes e servidores da rede. Baseado em axTLS e BearSSL.
-Atualizações de firmware over-The-Air (OTA) via HTTP(S) e MQTT(S).
O Sming tem um emulador de host que permite que bibliotecas e aplicativos de amostra sejam compilados em um sistema de
host Linux/Windows e sejam testados antes de enviá-los para um microcontrolador real.
osboxes@osboxes:~$ sudo chown $USER:$USER /opt osboxes@osboxes:~$ sudo apt-get install -y git osboxes@osboxes:~$ git clone https://github.com/SmingHub/Sming /opt/sming osboxes@osboxes:~$ cd /opt/sming osboxes@osboxes:~$ git checkout master osboxes@osboxes:~$ git pull
osboxes@osboxes:~$ ./opt/sming/Tools/export.sh
osboxes@osboxes:~$ ./opt/sming/Tools/install.shInstalando...
[sudo] password for osboxes: Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease Hit:3 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease Hit:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease Reading package lists... Done Reading package lists... Done Building dependency tree Reading state information... Done python3 is already the newest version (3.8.2-0ubuntu2). python3 set to manually installed. unzip is already the newest version (6.0-25ubuntu1). unzip set to manually installed. wget is already the newest version (1.20.3-1ubuntu1). wget set to manually installed. git is already the newest version (1:2.25.1-1ubuntu3.1). The following additional packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu build-essential cmake-data cpp-9 dpkg-dev fakeroot g++-9 g++-9-multilib gcc gcc-10-base gcc-9 gcc-9-base gcc-9-multilib gcc-multilib lib32asan5 lib32atomic1 lib32gcc-9-dev lib32gcc-s1 lib32gomp1 lib32itm1 lib32quadmath0 lib32stdc++-9-dev lib32stdc++6 lib32ubsan1 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6 libc6-dbg libc6-dev libc6-dev-i386 libc6-dev-x32 libc6-i386 libc6-x32 libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libcurl4 libexpat1-dev libfakeroot libgcc-9-dev libgcc-s1 libgomp1 libitm1 libjsoncpp1 libllvm8 liblsan0 libpython3-dev libpython3.8 libpython3.8-dev libpython3.8-minimal libpython3.8-stdlib libquadmath0 librhash0 libstdc++-9-dev libstdc++6 libtsan0 libubsan1 libx32asan5 libx32atomic1 libx32gcc-9-dev libx32gcc-s1 libx32gomp1 libx32itm1 libx32quadmath0 libx32stdc++-9-dev libx32stdc++6 libx32ubsan1 linux-libc-dev manpages-dev python-pip-whl python3-dev python3-distutils python3-wheel python3.8 python3.8-dev python3.8-minimal zlib1g zlib1g-dev Suggested packages: binutils-doc cmake-doc ninja-build gcc-9-locales debian-keyring gcc-9-doc lib32stdc++6-9-dbg libx32stdc++6-9-dbg autoconf automake libtool flex bison gcc-doc glibc-doc libstdc++-9-doc make-doc python-setuptools-doc python3.8-venv python3.8-doc binfmt-support The following NEW packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu build-essential clang-format-8 cmake cmake-data curl dpkg-dev fakeroot g++ g++-9 g++-9-multilib g++-multilib gcc gcc-9 gcc-9-multilib gcc-multilib lib32asan5 lib32atomic1 lib32gcc-9-dev lib32gcc-s1 lib32gomp1 lib32itm1 lib32quadmath0 lib32stdc++-9-dev lib32stdc++6 lib32ubsan1 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libc6-dev-i386 libc6-dev-x32 libc6-i386 libc6-x32 libcrypt-dev libctf-nobfd0 libctf0 libexpat1-dev libfakeroot libgcc-9-dev libitm1 libjsoncpp1 libllvm8 liblsan0 libpython3-dev libpython3.8-dev libquadmath0 librhash0 libstdc++-9-dev libtsan0 libubsan1 libx32asan5 libx32atomic1 libx32gcc-9-dev libx32gcc-s1 libx32gomp1 libx32itm1 libx32quadmath0 libx32stdc++-9-dev libx32stdc++6 libx32ubsan1 linux-libc-dev make manpages-dev python-pip-whl python3-dev python3-distutils python3-pip python3-setuptools python3-wheel python3.8-dev zlib1g-dev The following packages will be upgraded: cpp-9 gcc-10-base gcc-9-base libc6 libc6-dbg libcc1-0 libcurl4 libgcc-s1 libgomp1 libpython3.8 libpython3.8-minimal libpython3.8-stdlib libstdc++6 python3.8 python3.8-minimal zlib1g 16 upgraded, 78 newly installed, 0 to remove and 461 not upgraded. Need to get 104 MB of archives. After this operation, 398 MB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libc6-dbg amd64 2.31-0ubuntu9.2 [10.5 MB] Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libgomp1 amd64 10.2.0-5ubuntu1~20.04 [102 kB] Get:3 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 gcc-10-base amd64 10.2.0-5ubuntu1~20.04 [19.7 kB] Get:4 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libgcc-s1 amd64 10.2.0-5ubuntu1~20.04 [41.6 kB] . . . Installing collected packages: pyparsing, pyelftools, click Successfully installed click-7.1.2 pyelftools-0.27 pyparsing-2.3.1 Installation complete You may need to set environment variables: source /opt/sming/Sming/../Tools/export.sh
osboxes@osboxes:/opt/sming$ cd Tools
osboxes@osboxes:/opt/sming/Tools$ source export.sh
osboxes@osboxes:/opt/sming/Tools$
Arquitetura ESP32 (u-blox NINA W106)
Arquitetura Sming Esp32 Suporte à construção de Sming para a arquitetura Esp32. Variáveis de Build IDF_PATH Ele contém o diretório base para o conjunto de ferramentas ESP-IDF usado para construir a estrutura. Esta variável é necessária e deve ser definida de acordo. Requisitos Para poder compilar para a arquitetura ESP32, você deve ter o ESP-IDF v4.1 instalado. Os instaladores do Sming podem fazer isso por você. Você pode encontrar mais detalhes na documentação do ESP-IDF. Bulding Certifique-se de que o IDF_PATH esteja definido. Certifique-se também de que as outras variáveis de ambiente ESP-IDF estão definidas. No Linux, isso pode ser feito usando o seguinte comando: source $SMING_HOME/Tools/export.sh Construa a estrutura e o aplicativo como de costume, especificando SMING_ARCH = Esp32. Por exemplo: cd $SMING_HOME/../samples/Basic_Serial make SMING_ARCH=Esp32 Isso cria o aplicativo. Depois de construído, o aplicativo precisa ser instalado em um microcontrolador Esp32 real para ser executado. O piscar pode ser feito usando o seguinte comando: make flash
SDK Sming vem com bibliotecas pré-compiladas e arquivos de configuração. Se necessário, você pode reconfigurar o ESP-IDF usando o comando abaixo: make SMING_ARCH=Esp32 sdk-menuconfig Uma recompilação é necessária após a alteração da configuração. Isso pode ser feito com o seguinte comando: make SMING_ARCH=Esp32 sdk-build Se você quiser voltar a usar o SDK pré-compilado padrão, emita o seguinte comando: make SMING_ARCH = Esp32 sdk-default
Exemplo make SMING_ARCH=Esp32 COM_PORT=/dev/ttyUSB3 COM_SPEED_ESPTOOL=921600Compilando o exemplo Blink
Código
#include <SmingCore.h> #define LED_PIN 2 // GPIO2 Timer procTimer; bool state = true; void blink() { digitalWrite(LED_PIN, state); state = !state; } void init() { pinMode(LED_PIN, OUTPUT); procTimer.initializeMs(1000, blink).start(); }
osboxes@osboxes:/opt/sming/samples/Basic_Blink$ ls /dev/ttyU* /dev/ttyUSB0 osboxes@osboxes:/opt/sming/samples/Basic_Blink$ make flash SMING_ARCH=Esp32 COM_PORT=/dev/ttyUSB0 COM_SPEED_ESPTOOL=921600
Basic_Blink: Invoking 'flash' for Esp32 (debug) architecture make components application make[1]: Entering directory '/opt/sming/samples/Basic_Blink' Building /opt/sming/samples/Basic_Blink/out/Esp32/debug/lib/clib-App-4861c1f9ec77f6a75680a417f6cbe1c6.a make[2]: Nothing to be done for 'build'. Validating hardware config 'standard' Verifying partition table... Writing to 'out/Esp32/debug/firmware/partitions.bin' SSL support disabled Basic_Blink: Linking out/Esp32/debug/build/app.out Section| Description| Start (hex)| End (hex)|Used space ------------------------------------------------------------------------------ data| Initialized Data (RAM)| 3FFB0000| 3FFB317D| 12669 rodata| ReadOnly Data (SPI)| 3F400020| 3F4160E4| 90308 bss| Uninitialized Data (RAM)| 3FFB3180| 3FFB82A8| 20776 iram_text| Cached Code (IRAM)| 40080400| 4009505C| 85084 text| Uncached Code (SPI)| 400D0020| 4013FCAB| 457867 Total Used RAM : 33445 Free RAM : 302427 Free IRam : 45988 esptool.py v3.0 make[1]: Leaving directory '/opt/sming/samples/Basic_Blink' Killing Terminal to free /dev/ttyUSB0 make: [/opt/sming/Sming/Components/terminal/component.mk:32: kill_term] Killed (ignored) WriteFlash 0x1000=/opt/sming/Sming/out/Esp32/debug/build/esp32/sdk/bootloader/bootloader.bin
0x00008000=out/Esp32/debug/firmware/partitions.bin 0x00010000=out/Esp32/debug/firmware/app.bin /usr/bin/python3 /opt/sming/Sming/Components/esptool/esptool/esptool.py -p /dev/ttyUSB0 -b 921600 --chip esp32 --before
default_reset --after hard_reset write_flash -z -fs 4MB -ff 40m -fm dio 0x1000
/opt/sming/Sming/out/Esp32/debug/build/esp32/sdk/bootloader/bootloader.bin 0x00008000
out/Esp32/debug/firmware/partitions.bin 0x00010000 out/Esp32/debug/firmware/app.bin esptool.py v3.0 Serial port /dev/ttyUSB0 Connecting........_____....._ Chip is ESP32-D0WDQ6 (revision 1) Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None Crystal is 40MHz MAC: a4:cf:12:75:31:c8 Uploading stub... Running stub... Stub running... Changing baud rate to 921600 Changed. Configuring flash size... Flash params set to 0x0220 Compressed 23952 bytes to 14906... Wrote 23952 bytes (14906 compressed) at 0x00001000 in 0.2 seconds (effective 887.1 kbit/s)... Hash of data verified. Compressed 3072 bytes to 121... Wrote 3072 bytes (121 compressed) at 0x00008000 in 0.0 seconds (effective 2182.3 kbit/s)... Hash of data verified. Compressed 647072 bytes to 416450... Wrote 647072 bytes (416450 compressed) at 0x00010000 in 5.6 seconds (effective 927.7 kbit/s)... Hash of data verified. Leaving... Hard resetting via RTS pin... /usr/bin/python3 -m serial.tools.miniterm --raw --encoding ascii /dev/ttyUSB0 115200 --- Miniterm on /dev/ttyUSB0 115200,8,N,1 --- --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H --- I (357) esp_image: segment 5: paddr=0x0009fcb4 vaddr=0x40086d9c size=0x0e2c0 ( 58048) load I (394) boot: Loaded app from partition at offset 0x10000 I (394) boot: Disabling RNG early entropy source... I (394) cpu_start: Pro cpu up. I (398) cpu_start: Application information: I (403) cpu_start: Project name: Sming I (408) cpu_start: App version: 4.3.0 I (412) cpu_start: Compile time: Apr 5 2021 15:50:07 I (418) cpu_start: ELF file SHA256: 179a9d0196742c03... I (424) cpu_start: ESP-IDF: v4.1.1-250-ga92185263 I (431) cpu_start: Starting app cpu, entry point is 0x400811f0 I (0) cpu_start: App cpu up. I (441) heap_init: Initializing. RAM available for dynamic allocation: I (448) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (454) heap_init: At 3FFB82A8 len 00027D58 (159 KiB): DRAM I (460) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM I (466) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (473) heap_init: At 4009505C len 0000AFA4 (43 KiB): IRAM I (479) cpu_start: Pro cpu start user code I (497) spi_flash: detected chip: generic I (498) spi_flash: flash io: dio I (498) cpu_start: Starting scheduler on PRO CPU. I (0) cpu_start: Starting scheduler on APP CPU. I (60) wifi:wifi driver task: 3ffbb1c4, prio:23, stack:6656, core=0 I (627) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE I (637) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE I (667) wifi:wifi firmware version: ce1f327 I (667) wifi:config NVS flash: enabled I (667) wifi:config nano formating: disabled I (667) wifi:Init data frame dynamic rx buffer num: 32 I (667) wifi:Init management frame dynamic rx buffer num: 32 I (677) wifi:Init management short buffer num: 32 I (677) wifi:Init dynamic tx buffer num: 32 I (687) wifi:Init static rx buffer size: 1600 I (687) wifi:Init static rx buffer num: 10 I (687) wifi:Init dynamic rx buffer num: 32 I (697) wifi_init: rx ba win: 6 I (697) wifi_init: tcpip mbox: 32 I (707) wifi_init: udp mbox: 6 I (707) wifi_init: tcp mbox: 6 I (707) wifi_init: tcp tx win: 5744 I (717) wifi_init: tcp rx win: 5744 I (717) wifi_init: tcp mss: 1440 I (727) wifi_init: WiFi IRAM OP enabled I (727) wifi_init: WiFi RX IRAM OP enabledPara sair do TERMINAL (CRTL-T Q)
Execução
Exemploshttps://github.com/SmingHub/SmingBasic Blink
Blinking é alguma coisa como "Hello World".
Simple GPIO Input/Output
#define LED_PIN 2 // GPIO2 ... pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, HIGH);Start Serial Communication
Serial.begin(9600); Serial.println("Hello Sming! Let's do smart things.");Connect to WiFi
WifiStation.enable(true); WifiStation.config("LOCAL-NETWORK", "123456789087"); // Put your SSID and password hereRead DHT22 sensor
#include <Libraries/DHTesp/DHTesp.h> // This is just a popular Arduino library! #define DHT_PIN 0 // GPIO0 DHTesp dht; void init() { dht.setup(DHT_PIN, DHTesp::DHT22); float h = dht.getHumidity(); float t = dht.getTemperature(); }HTTP Client
HttpClient thingSpeak; ... thingSpeak.downloadString("http://api.thingspeak.com/update?key=XXXXXXX&field1=" + String(sensorValue), onDataSent); void onDataSent(HttpClient& client, bool successful) { if (successful) { Serial.println("Successful!"); } else { Serial.println("Failed"); } }OTA Application Update Based on rBoot
void OtaUpdate() { uint8 slot; rboot_config bootconf; Serial.println("Updating..."); // need a clean object, otherwise if run before and failed will not run again if (otaUpdater) { delete otaUpdater; } otaUpdater = new RbootHttpUpdater(); // select rom slot to flash bootconf = rboot_get_config(); slot = bootconf.current_rom; if (slot == 0) { slot = 1; } else { slot = 0; } // flash rom to position indicated in the rBoot config rom table otaUpdater->addItem(bootconf.roms[slot], ROM_0_URL); // and/or set a callback (called on failure or success without switching requested) otaUpdater->setCallback(OtaUpdate_CallBack); // start update otaUpdater->start(); }HTTP Server
server.listen(80); server.paths.set("/", onIndex); server.paths.set("/hello", onHello); server.paths.setDefault(onFile); Serial.println("=== WEB SERVER STARTED ==="); Serial.println(WifiStation.getIP()); ... void onIndex(HttpRequest &request, HttpResponse &response) { TemplateFileStream *tmpl = new TemplateFileStream("index.html"); auto &vars = tmpl->variables(); vars["counter"] = String(counter); vars["IP"] = WifiStation.getIP().toString(); vars["MAC"] = WifiStation.getMAC(); response.sendTemplate(tmpl); } void onFile(HttpRequest &request, HttpResponse &response) { String file = request.getPath(); if (file[0] == '/') file = file.substring(1); response.setCache(86400, true); response.sendFile(file); }For more examples take a look at the HttpServer_ConfigNetwork, HttpServer_Bootstrap, HttpServer_WebSockets and HttpServer_AJAX samples.
Email Client
SmtpClient emailClient; emailClient.connect(Url("smtp://user:password@domain.com")); MailMessage* mail = new MailMessage(); mail->from = "developers@sming"; mail->to = "iot-developers@world"; mail->subject = "Greetings from Sming"; mail->setBody("Hello"); FileStream* file= new FileStream("image.png"); mail->addAttachment(file); emailClient.onMessageSent(onMailSent); emailClient.send(mail); ... int onMailSent(SmtpClient& client, int code, char* status) { MailMessage* mail = client.getCurrentMessage(); ... if(!client.countPending()) { client.quit(); } return 0; }suporte@smartcore.com.brDÚVIDASREFERÊNCIASSobre a SMARTCORE
A SmartCore fornece módulos para comunicação wireless, biometria, conectividade, rastreamento e automação.Nosso portfólio inclui modem 2G/3G/4G/NB-IoT/Cat.M, satelital, módulos WiFi, Bluetooth, GNSS / GPS, Sigfox, LoRa, leitor de cartão, leitor QR code, mecanismo de impressão, mini-board PC, antena, pigtail, LCD, bateria, repetidor GPS e sensores.Mais detalhes em www.smartcore.com.br
Nenhum comentário:
Postar um comentário