Compare commits

...

17 Commits

31 changed files with 3805 additions and 647 deletions

View File

@ -0,0 +1,227 @@
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# Arduino SAMD Core and platform.
#
# For more info:
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
name=Seeed SAMD (32-bits ARM Cortex-M0+ and Cortex-M4) Boards
version=1.7.9
# Compile variables
# -----------------
compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall -Wno-expansion-to-defined
compiler.warning_flags.all=-Wall -Wextra -Wno-expansion-to-defined
compiler.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
compiler.c.cmd=arm-none-eabi-gcc
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -D__SKETCH_NAME__="""{build.project_name}"""
compiler.c.elf.cmd=arm-none-eabi-g++
compiler.c.elf.flags=-Os -Wl,--gc-sections -save-temps
compiler.S.cmd=arm-none-eabi-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
compiler.cpp.cmd=arm-none-eabi-g++
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu++14 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -D__SKETCH_NAME__="""{build.project_name}"""
compiler.ar.cmd=arm-none-eabi-ar
compiler.ar.flags=rcs
compiler.objcopy.cmd=arm-none-eabi-objcopy
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
compiler.elf2hex.bin.flags=-O binary
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
compiler.elf2hex.cmd=arm-none-eabi-objcopy
compiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -u _printf_float -u _scanf_float -Wl,--wrap,_write -u __wrap__write
compiler.size.cmd=arm-none-eabi-size
compiler.define=-DARDUINO=
compiler.readelf.cmd=arm-none-eabi-readelf
# this can be overriden in boards.txt
build.extra_flags=
build.project_flags=
build.cache_flags=
build.flags.optimize=
build.flags.maxspi=
build.flags.maxqspi=
build.flags.usbstack=
build.flags.debug=
# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
#compiler.c.elf.extra_flags=-v
compiler.cpp.extra_flags=
compiler.S.extra_flags=
compiler.ar.extra_flags=
compiler.elf2hex.extra_flags=
compiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-5.4.0.path}/CMSIS/Core/Include/" "-I{runtime.tools.CMSIS-5.4.0.path}/CMSIS/DSP/Include/" "-I{runtime.tools.CMSIS-Atmel-1.2.1.path}/CMSIS-Atmel/CMSIS/Device/ATMEL/"
compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-5.4.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
compiler.libraries.ldflags=
# USB Flags
# ---------
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON -DUSB_CONFIG_POWER={build.usb_power} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' {build.flags.usbstack} {build.flags.debug} "-I{build.core.path}/TinyUSB" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src"
# Default advertised device power setting in mA
build.usb_power=100
# Default usb manufacturer will be replaced at compile time using
# numeric vendor ID if available or by board's specific value.
build.usb_manufacturer="Unknown"
# Compile patterns
# ----------------
## Compile c files
## KH Add -DBOARD_NAME="{build.board}"
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.project_flags} {build.cache_flags} {build.flags.debug} {build.flags.optimize} {build.flags.maxspi} {build.flags.maxqspi} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
## Compile c++ files
## KH Add -DBOARD_NAME="{build.board}"
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.project_flags} {build.cache_flags} {build.flags.debug} {build.flags.optimize} {build.flags.maxspi} {build.flags.maxqspi} {build.extra_flags} {build.project_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
## Compile S files
## KH Add -DBOARD_NAME="{build.board}"
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.project_flags} {build.cache_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
## Create archives
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
archive_file_path={build.path}/{archive_file}
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} -Wl,--start-group {compiler.arm.cmsis.ldflags} "-L{build.variant.path}" -lm "{build.path}/{archive_file}" -Wl,--end-group
## Create output (bin file)
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.bin.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
## Create output (hex file)
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
build.preferred_out_format=bin
## Save hex
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=\.text\s+([0-9]+).*
#
# BOSSA
#
tools.bossac.path={runtime.tools.bossac-1.7.0-arduino3.path}
tools.bossac.cmd=bossac
tools.bossac.cmd.windows=bossac.exe
tools.bossac.upload.params.verbose=-i -d
tools.bossac.upload.params.quiet=
tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -i -e -w -v "{build.path}/{build.project_name}.bin" -R
tools.bossac_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
tools.bossac.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
tools.bossac.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
# v1.8.0
tools.bossac18.path={runtime.tools.bossac-1.8.0-48-gb176eee.path}
tools.bossac18.cmd=bossac
tools.bossac18.upload.params.verbose=-i -d
tools.bossac18.upload.params.quiet=
tools.bossac18.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U -i --offset={upload.offset} -w -v "{build.path}/{build.project_name}.bin" -R
tools.bossac18.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
tools.bossac18.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
#
# BOSSA (ignore binary size)
#
tools.bossacI.path={runtime.tools.bossac-1.7.0-arduino3.path}
tools.bossacI.cmd=bossac
tools.bossacI.cmd.windows=bossac.exe
tools.bossacI.upload.params.verbose=-i -d
tools.bossacI.upload.params.quiet=
tools.bossacI.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -I -U {upload.native_usb} -i -e -w "{build.path}/{build.project_name}.bin" -R
tools.bossacI_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
tools.bossacI.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
tools.bossacI.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
#
# OpenOCD sketch upload
#
tools.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}
tools.openocd.cmd=bin/openocd
tools.openocd.cmd.windows=bin/openocd.exe
tools.openocd.upload.params.verbose=-d2
tools.openocd.upload.params.quiet=-d0
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset 0x2000; shutdown"
tools.openocd.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
tools.openocd.upload.network_pattern={network_cmd} -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
tools.openocd.program.params.verbose=-d2
tools.openocd.program.params.quiet=-d0
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
tools.openocd.erase.params.verbose=-d3
tools.openocd.erase.params.quiet=-d0
tools.openocd.erase.pattern=
tools.openocd.bootloader.params.verbose=-d2
tools.openocd.bootloader.params.quiet=-d0
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
#
# OpenOCD sketch upload - version with configurable bootloader size
# FIXME: this programmer is a workaround for default options being overwritten by uploadUsingPreferences
#
tools.openocd-withbootsize.path={runtime.tools.openocd-0.10.0-arduino7.path}
tools.openocd-withbootsize.cmd=bin/openocd
tools.openocd-withbootsize.cmd.windows=bin/openocd.exe
tools.openocd-withbootsize.upload.params.verbose=-d2
tools.openocd-withbootsize.upload.params.quiet=-d0
tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
tools.openocd-withbootsize.program.params.verbose=-d2
tools.openocd-withbootsize.program.params.quiet=-d0
tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
tools.openocd-withbootsize.erase.params.verbose=-d3
tools.openocd-withbootsize.erase.params.quiet=-d0
tools.openocd-withbootsize.erase.pattern=
tools.openocd-withbootsize.bootloader.params.verbose=-d2
tools.openocd-withbootsize.bootloader.params.quiet=-d0
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"

View File

@ -0,0 +1,649 @@
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
# Copyright (c) 2016 Sandeep Mistry All right reserved.
# Copyright (c) 2017 Adafruit Industries. All right reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
menu.softdevice=Bootloader
menu.debug=Debug
# ----------------------------------
# Bluefruit Feather nRF52832
# ----------------------------------
feather52832.name=Adafruit Feather nRF52832
feather52832.bootloader.tool=bootburn
# Upload
feather52832.upload.tool=nrfutil
feather52832.upload.protocol=nrfutil
feather52832.upload.use_1200bps_touch=false
feather52832.upload.wait_for_upload_port=false
feather52832.upload.native_usb=false
feather52832.upload.maximum_size=290816
feather52832.upload.maximum_data_size=52224
# Build
feather52832.build.mcu=cortex-m4
feather52832.build.f_cpu=64000000
feather52832.build.board=NRF52832_FEATHER
feather52832.build.core=nRF5
feather52832.build.variant=feather_nrf52832
feather52832.build.usb_manufacturer="Adafruit LLC"
feather52832.build.usb_product="Feather nRF52832"
feather52832.build.extra_flags=-DNRF52832_XXAA -DNRF52
feather52832.build.ldscript=nrf52832_s132_v6.ld
# SofDevice Menu
feather52832.menu.softdevice.s132v6=0.3.2 SoftDevice s132 6.1.1
feather52832.menu.softdevice.s132v6.build.sd_name=s132
feather52832.menu.softdevice.s132v6.build.sd_version=6.1.1
feather52832.menu.softdevice.s132v6.build.sd_fwid=0x00B7
# Debug Menu
feather52832.menu.debug.l0=Level 0 (Release)
feather52832.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
feather52832.menu.debug.l1=Level 1 (Error Message)
feather52832.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
feather52832.menu.debug.l2=Level 2 (Full Debug)
feather52832.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
feather52832.menu.debug.l3=Level 3 (Segger SystemView)
feather52832.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
feather52832.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ----------------------------------
# Bluefruit Feather nRF52840 Express
# ----------------------------------
feather52840.name=Adafruit Feather nRF52840 Express
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
feather52840.vid.0=0x239A
feather52840.pid.0=0x8029
feather52840.vid.1=0x239A
feather52840.pid.1=0x0029
feather52840.vid.2=0x239A
feather52840.pid.2=0x002A
feather52840.vid.3=0x239A
feather52840.pid.3=0x802A
# Upload
feather52840.bootloader.tool=bootburn
feather52840.upload.tool=nrfutil
feather52840.upload.protocol=nrfutil
feather52840.upload.use_1200bps_touch=true
feather52840.upload.wait_for_upload_port=true
feather52840.upload.maximum_size=815104
feather52840.upload.maximum_data_size=237568
# Build
feather52840.build.mcu=cortex-m4
feather52840.build.f_cpu=64000000
feather52840.build.board=NRF52840_FEATHER
feather52840.build.core=nRF5
feather52840.build.variant=feather_nrf52840_express
feather52840.build.usb_manufacturer="Adafruit LLC"
feather52840.build.usb_product="Feather nRF52840 Express"
feather52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
feather52840.build.ldscript=nrf52840_s140_v6.ld
feather52840.build.vid=0x239A
feather52840.build.pid=0x8029
# SofDevice Menu
feather52840.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
feather52840.menu.softdevice.s140v6.build.sd_name=s140
feather52840.menu.softdevice.s140v6.build.sd_version=6.1.1
feather52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
feather52840.menu.debug.l0=Level 0 (Release)
feather52840.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
feather52840.menu.debug.l1=Level 1 (Error Message)
feather52840.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
feather52840.menu.debug.l2=Level 2 (Full Debug)
feather52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
feather52840.menu.debug.l3=Level 3 (Segger SystemView)
feather52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
feather52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ----------------------------------
# Feather Bluefruit sense
# ----------------------------------
feather52840sense.name=Adafruit Feather Bluefruit Sense
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
feather52840sense.vid.0=0x239A
feather52840sense.pid.0=0x8087
feather52840sense.vid.1=0x239A
feather52840sense.pid.1=0x0087
feather52840sense.vid.2=0x239A
feather52840sense.pid.2=0x0088
feather52840sense.vid.3=0x239A
feather52840sense.pid.3=0x8088
# Upload
feather52840sense.bootloader.tool=bootburn
feather52840sense.upload.tool=nrfutil
feather52840sense.upload.protocol=nrfutil
feather52840sense.upload.use_1200bps_touch=true
feather52840sense.upload.wait_for_upload_port=true
feather52840sense.upload.maximum_size=815104
feather52840sense.upload.maximum_data_size=237568
# Build
feather52840sense.build.mcu=cortex-m4
feather52840sense.build.f_cpu=64000000
feather52840sense.build.board=NRF52840_FEATHER_SENSE
feather52840sense.build.core=nRF5
feather52840sense.build.variant=feather_nrf52840_sense
feather52840sense.build.usb_manufacturer="Adafruit LLC"
feather52840sense.build.usb_product="Feather nRF52840 Sense"
feather52840sense.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
feather52840sense.build.ldscript=nrf52840_s140_v6.ld
feather52840sense.build.vid=0x239A
feather52840sense.build.pid=0x8087
# SofDevice Menu
feather52840sense.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
feather52840sense.menu.softdevice.s140v6.build.sd_name=s140
feather52840sense.menu.softdevice.s140v6.build.sd_version=6.1.1
feather52840sense.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
feather52840sense.menu.debug.l0=Level 0 (Release)
feather52840sense.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
feather52840sense.menu.debug.l1=Level 1 (Error Message)
feather52840sense.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
feather52840sense.menu.debug.l2=Level 2 (Full Debug)
feather52840sense.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
feather52840sense.menu.debug.l3=Level 3 (Segger SystemView)
feather52840sense.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
feather52840sense.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ---------------------------------------------
# Bluefruit ItsyBitsy nRF52840 Express
# ---------------------------------------------
itsybitsy52840.name=Adafruit ItsyBitsy nRF52840 Express
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
itsybitsy52840.vid.0=0x239A
itsybitsy52840.pid.0=0x8051
itsybitsy52840.vid.1=0x239A
itsybitsy52840.pid.1=0x0051
itsybitsy52840.vid.2=0x239A
itsybitsy52840.pid.2=0x0052
itsybitsy52840.vid.3=0x239A
itsybitsy52840.pid.3=0x8052
# Upload
itsybitsy52840.bootloader.tool=bootburn
itsybitsy52840.upload.tool=nrfutil
itsybitsy52840.upload.protocol=nrfutil
itsybitsy52840.upload.use_1200bps_touch=true
itsybitsy52840.upload.wait_for_upload_port=true
itsybitsy52840.upload.maximum_size=815104
itsybitsy52840.upload.maximum_data_size=237568
# Build
itsybitsy52840.build.mcu=cortex-m4
itsybitsy52840.build.f_cpu=64000000
itsybitsy52840.build.board=NRF52840_ITSYBITSY
itsybitsy52840.build.core=nRF5
itsybitsy52840.build.variant=itsybitsy_nrf52840_express
itsybitsy52840.build.usb_manufacturer="Adafruit LLC"
itsybitsy52840.build.usb_product="ItsyBitsy nRF52840 Express"
itsybitsy52840.build.extra_flags=-DNRF52840_XXAA -DARDUINO_NRF52_ITSYBITSY {build.flags.usb}
itsybitsy52840.build.ldscript=nrf52840_s140_v6.ld
itsybitsy52840.build.vid=0x239A
itsybitsy52840.build.pid=0x8051
# SofDevice Menu
itsybitsy52840.menu.softdevice.s140v6=0.2.11 SoftDevice s140 6.1.1
itsybitsy52840.menu.softdevice.s140v6.build.sd_name=s140
itsybitsy52840.menu.softdevice.s140v6.build.sd_version=6.1.1
itsybitsy52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
itsybitsy52840.menu.debug.l0=Level 0 (Release)
itsybitsy52840.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
itsybitsy52840.menu.debug.l1=Level 1 (Error Message)
itsybitsy52840.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
itsybitsy52840.menu.debug.l2=Level 2 (Full Debug)
itsybitsy52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
itsybitsy52840.menu.debug.l3=Level 3 (Segger SystemView)
itsybitsy52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
itsybitsy52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ---------------------------------------------
# Bluefruit Circuit Playground nRF52840 Express
# ---------------------------------------------
cplaynrf52840.name=Adafruit Circuit Playground Bluefruit
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
cplaynrf52840.vid.0=0x239A
cplaynrf52840.pid.0=0x8045
cplaynrf52840.vid.1=0x239A
cplaynrf52840.pid.1=0x0045
cplaynrf52840.vid.2=0x239A
cplaynrf52840.pid.2=0x0046
cplaynrf52840.vid.3=0x239A
cplaynrf52840.pid.3=0x8046
# Upload
cplaynrf52840.bootloader.tool=bootburn
cplaynrf52840.upload.tool=nrfutil
cplaynrf52840.upload.protocol=nrfutil
cplaynrf52840.upload.use_1200bps_touch=true
cplaynrf52840.upload.wait_for_upload_port=true
cplaynrf52840.upload.maximum_size=815104
cplaynrf52840.upload.maximum_data_size=237568
# Build
cplaynrf52840.build.mcu=cortex-m4
cplaynrf52840.build.f_cpu=64000000
cplaynrf52840.build.board=NRF52840_CIRCUITPLAY
cplaynrf52840.build.core=nRF5
cplaynrf52840.build.variant=circuitplayground_nrf52840
cplaynrf52840.build.usb_manufacturer="Adafruit LLC"
cplaynrf52840.build.usb_product="Circuit Playground Bluefruit"
cplaynrf52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
cplaynrf52840.build.ldscript=nrf52840_s140_v6.ld
cplaynrf52840.build.vid=0x239A
cplaynrf52840.build.pid=0x8045
# SofDevice Menu
cplaynrf52840.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
cplaynrf52840.menu.softdevice.s140v6.build.sd_name=s140
cplaynrf52840.menu.softdevice.s140v6.build.sd_version=6.1.1
cplaynrf52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
cplaynrf52840.menu.debug.l0=Level 0 (Release)
cplaynrf52840.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
cplaynrf52840.menu.debug.l1=Level 1 (Error Message)
cplaynrf52840.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
cplaynrf52840.menu.debug.l2=Level 2 (Full Debug)
cplaynrf52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
cplaynrf52840.menu.debug.l3=Level 3 (Segger SystemView)
cplaynrf52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
cplaynrf52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ---------------------------------------------
# Clue nRF52840
# ---------------------------------------------
cluenrf52840.name=Adafruit CLUE
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
cluenrf52840.vid.0=0x239A
cluenrf52840.pid.0=0x8072
cluenrf52840.vid.1=0x239A
cluenrf52840.pid.1=0x0072
cluenrf52840.vid.2=0x239A
cluenrf52840.pid.2=0x0071
cluenrf52840.vid.3=0x239A
cluenrf52840.pid.3=0x8071
# Upload
cluenrf52840.bootloader.tool=bootburn
cluenrf52840.upload.tool=nrfutil
cluenrf52840.upload.protocol=nrfutil
cluenrf52840.upload.use_1200bps_touch=true
cluenrf52840.upload.wait_for_upload_port=true
cluenrf52840.upload.maximum_size=815104
cluenrf52840.upload.maximum_data_size=237568
# Build
cluenrf52840.build.mcu=cortex-m4
cluenrf52840.build.f_cpu=64000000
cluenrf52840.build.board=NRF52840_CLUE
cluenrf52840.build.core=nRF5
cluenrf52840.build.variant=clue_nrf52840
cluenrf52840.build.usb_manufacturer="Adafruit LLC"
cluenrf52840.build.usb_product="CLUE"
cluenrf52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
cluenrf52840.build.ldscript=nrf52840_s140_v6.ld
cluenrf52840.build.vid=0x239A
cluenrf52840.build.pid=0x8071
# SofDevice Menu
cluenrf52840.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
cluenrf52840.menu.softdevice.s140v6.build.sd_name=s140
cluenrf52840.menu.softdevice.s140v6.build.sd_version=6.1.1
cluenrf52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
cluenrf52840.menu.debug.l0=Level 0 (Release)
cluenrf52840.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
cluenrf52840.menu.debug.l1=Level 1 (Error Message)
cluenrf52840.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
cluenrf52840.menu.debug.l2=Level 2 (Full Debug)
cluenrf52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
cluenrf52840.menu.debug.l3=Level 3 (Segger SystemView)
cluenrf52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
cluenrf52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ----------------------------------
# Bluefruit Metro nRF52840 Express
# ----------------------------------
metro52840.name=Adafruit Bluefruit Metro nRF52840 Express
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
metro52840.vid.0=0x239A
metro52840.pid.0=0x803F
metro52840.vid.1=0x239A
metro52840.pid.1=0x003F
metro52840.vid.2=0x239A
metro52840.pid.2=0x0040
metro52840.vid.3=0x239A
metro52840.pid.3=0x8040
# Upload
metro52840.bootloader.tool=bootburn
metro52840.upload.tool=nrfutil
metro52840.upload.protocol=nrfutil
metro52840.upload.use_1200bps_touch=true
metro52840.upload.wait_for_upload_port=true
metro52840.upload.maximum_size=815104
metro52840.upload.maximum_data_size=237568
# Build
metro52840.build.mcu=cortex-m4
metro52840.build.f_cpu=64000000
metro52840.build.board=NRF52840_METRO
metro52840.build.core=nRF5
metro52840.build.variant=metro_nrf52840_express
metro52840.build.usb_manufacturer="Adafruit LLC"
metro52840.build.usb_product="Metro nRF52840 Express"
metro52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
metro52840.build.ldscript=nrf52840_s140_v6.ld
metro52840.build.vid=0x239A
metro52840.build.pid=0x803F
# SofDevice Menu
metro52840.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
metro52840.menu.softdevice.s140v6.build.sd_name=s140
metro52840.menu.softdevice.s140v6.build.sd_version=6.1.1
metro52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
metro52840.menu.debug.l0=Level 0 (Release)
metro52840.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
metro52840.menu.debug.l1=Level 1 (Error Message)
metro52840.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
metro52840.menu.debug.l2=Level 2 (Full Debug)
metro52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
metro52840.menu.debug.l3=Level 3 (Segger SystemView)
metro52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
metro52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# -------------------------------------------------------
#
# Boards that aren't made by Adafruit
#
# -------------------------------------------------------
# ----------------------------------
# Nordic nRF52840DK (PCA10056)
# ----------------------------------
pca10056.name=Nordic nRF52840DK (PCA10056)
pca10056.bootloader.tool=bootburn
# Upload
pca10056.upload.tool=nrfutil
pca10056.upload.protocol=nrfutil
pca10056.upload.use_1200bps_touch=true
pca10056.upload.wait_for_upload_port=true
pca10056.upload.maximum_size=815104
pca10056.upload.maximum_data_size=237568
# Build
pca10056.build.mcu=cortex-m4
pca10056.build.f_cpu=64000000
pca10056.build.board=NRF52840_PCA10056
pca10056.build.core=nRF5
pca10056.build.variant=pca10056
pca10056.build.usb_manufacturer="Nordic"
pca10056.build.usb_product="nRF52840 DK"
pca10056.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
pca10056.build.ldscript=nrf52840_s140_v6.ld
pca10056.build.vid=0x239A
pca10056.build.pid=0x8029
# SofDevice Menu
pca10056.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
pca10056.menu.softdevice.s140v6.build.sd_name=s140
pca10056.menu.softdevice.s140v6.build.sd_version=6.1.1
pca10056.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
pca10056.menu.debug.l0=Level 0 (Release)
pca10056.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
pca10056.menu.debug.l1=Level 1 (Error Message)
pca10056.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
pca10056.menu.debug.l2=Level 2 (Full Debug)
pca10056.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
pca10056.menu.debug.l3=Level 3 (Segger SystemView)
pca10056.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
pca10056.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ----------------------------------
# Particle Xenon
# ----------------------------------
particle_xenon.name=Particle Xenon
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
particle_xenon.vid.0=0x239A
particle_xenon.pid.0=0x8029
particle_xenon.vid.1=0x239A
particle_xenon.pid.1=0x0029
particle_xenon.vid.2=0x239A
particle_xenon.pid.2=0x002A
particle_xenon.vid.3=0x239A
particle_xenon.pid.3=0x802A
# Upload
particle_xenon.bootloader.tool=bootburn
particle_xenon.upload.tool=nrfutil
particle_xenon.upload.protocol=nrfutil
particle_xenon.upload.use_1200bps_touch=true
particle_xenon.upload.wait_for_upload_port=true
particle_xenon.upload.maximum_size=815104
particle_xenon.upload.maximum_data_size=237568
# Build
particle_xenon.build.mcu=cortex-m4
particle_xenon.build.f_cpu=64000000
particle_xenon.build.board=PARTICLE_XENON
particle_xenon.build.core=nRF5
particle_xenon.build.variant=particle_xenon
particle_xenon.build.usb_manufacturer="Particle Industries"
particle_xenon.build.usb_product="Particle Xenon"
particle_xenon.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
particle_xenon.build.ldscript=nrf52840_s140_v6.ld
particle_xenon.build.vid=0x239A
particle_xenon.build.pid=0x8029
# SofDevice Menu
particle_xenon.menu.softdevice.s140v6=0.2.11 SoftDevice s140 6.1.1
particle_xenon.menu.softdevice.s140v6.build.sd_name=s140
particle_xenon.menu.softdevice.s140v6.build.sd_version=6.1.1
particle_xenon.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
particle_xenon.menu.debug.l0=Level 0 (Release)
particle_xenon.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
particle_xenon.menu.debug.l1=Level 1 (Error Message)
particle_xenon.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
particle_xenon.menu.debug.l2=Level 2 (Full Debug)
particle_xenon.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
particle_xenon.menu.debug.l3=Level 3 (Segger SystemView)
particle_xenon.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
particle_xenon.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ----------------------------------
# Raytac MDBT50Q - RX
# ----------------------------------
mdbt50qrx.name=Raytac MDBT50Q-RX Dongle
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
mdbt50qrx.vid.0=0x239A
mdbt50qrx.pid.0=0x8029
mdbt50qrx.vid.1=0x239A
mdbt50qrx.pid.1=0x0029
mdbt50qrx.vid.2=0x239A
mdbt50qrx.pid.2=0x002A
mdbt50qrx.vid.3=0x239A
mdbt50qrx.pid.3=0x802A
# Upload
mdbt50qrx.bootloader.tool=bootburn
mdbt50qrx.upload.tool=nrfutil
mdbt50qrx.upload.protocol=nrfutil
mdbt50qrx.upload.use_1200bps_touch=true
mdbt50qrx.upload.wait_for_upload_port=true
mdbt50qrx.upload.maximum_size=815104
mdbt50qrx.upload.maximum_data_size=237568
# Build
mdbt50qrx.build.mcu=cortex-m4
mdbt50qrx.build.f_cpu=64000000
mdbt50qrx.build.board=MDBT50Q_RX
mdbt50qrx.build.core=nRF5
mdbt50qrx.build.variant=raytac_mdbt50q_rx
mdbt50qrx.build.usb_manufacturer="Raytac Corporation"
mdbt50qrx.build.usb_product="Raytac MDBT50Q - RX"
mdbt50qrx.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
mdbt50qrx.build.ldscript=nrf52840_s140_v6.ld
mdbt50qrx.build.vid=0x239A
mdbt50qrx.build.pid=0x8029
# SofDevice Menu
mdbt50qrx.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
mdbt50qrx.menu.softdevice.s140v6.build.sd_name=s140
mdbt50qrx.menu.softdevice.s140v6.build.sd_version=6.1.1
mdbt50qrx.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
mdbt50qrx.menu.debug.l0=Level 0 (Release)
mdbt50qrx.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
mdbt50qrx.menu.debug.l1=Level 1 (Error Message)
mdbt50qrx.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
mdbt50qrx.menu.debug.l2=Level 2 (Full Debug)
mdbt50qrx.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
mdbt50qrx.menu.debug.l3=Level 3 (Segger SystemView)
mdbt50qrx.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
mdbt50qrx.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ----------------------------------
# NINA B302
# ----------------------------------
ninab302.name=NINA B302 ublox
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
ninab302.vid.0=0x239A
ninab302.pid.0=0x8029
ninab302.vid.1=0x239A
ninab302.pid.1=0x0029
ninab302.vid.2=0x7239A
ninab302.pid.2=0x002A
ninab302.vid.3=0x239A
ninab302.pid.3=0x802A
# Upload
ninab302.bootloader.tool=bootburn
ninab302.upload.tool=nrfutil
ninab302.upload.protocol=nrfutil
ninab302.upload.use_1200bps_touch=true
ninab302.upload.wait_for_upload_port=true
ninab302.upload.maximum_size=815104
ninab302.upload.maximum_data_size=237568
# Build
ninab302.build.mcu=cortex-m4
ninab302.build.f_cpu=64000000
ninab302.build.board=NINA_B302_ublox
ninab302.build.core=nRF5
ninab302.build.variant=NINA_B302_ublox
ninab302.build.usb_manufacturer="Nordic"
ninab302.build.usb_product="NINA B302 ublox"
ninab302.build.extra_flags=-DNRF52840_XXAA -DNINA_B302_ublox {build.flags.usb}
ninab302.build.ldscript=nrf52840_s140_v6.ld
ninab302.build.vid=0x239A
ninab302.build.pid=0x8029
# SofDevice Menu
ninab302.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1
ninab302.menu.softdevice.s140v6.build.sd_name=s140
ninab302.menu.softdevice.s140v6.build.sd_version=6.1.1
ninab302.menu.softdevice.s140v6.build.sd_fwid=0x00B6
# Debug Menu
ninab302.menu.debug.l0=Level 0 (Release)
ninab302.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
ninab302.menu.debug.l1=Level 1 (Error Message)
ninab302.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
ninab302.menu.debug.l2=Level 2 (Full Debug)
ninab302.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
ninab302.menu.debug.l3=Level 3 (Segger SystemView)
ninab302.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
ninab302.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
# ----------------------------------
# NINA B112
# ----------------------------------
ninab112.name=NINA B112 ublox
ninab112.bootloader.tool=bootburn
# Upload
ninab112.upload.tool=nrfutil
ninab112.upload.protocol=nrfutil
ninab112.upload.use_1200bps_touch=false
ninab112.upload.wait_for_upload_port=false
ninab112.upload.native_usb=false
ninab112.upload.maximum_size=290816
ninab112.upload.maximum_data_size=52224
# Build
ninab112.build.mcu=cortex-m4
ninab112.build.f_cpu=64000000
ninab112.build.board=NINA_B112_ublox
ninab112.build.core=nRF5
ninab112.build.variant=NINA_B112_ublox
feather52840.build.usb_manufacturer="Adafruit LLC"
feather52840.build.usb_product="Feather nRF52832"
ninab112.build.extra_flags=-DNRF52832_XXAA -DNINA_B112_ublox -DNRF52
ninab112.build.ldscript=nrf52832_s132_v6.ld
# SofDevice Menu
ninab112.menu.softdevice.s132v6=0.3.2 SoftDevice s132 6.1.1
ninab112.menu.softdevice.s132v6.build.sd_name=s132
ninab112.menu.softdevice.s132v6.build.sd_version=6.1.1
ninab112.menu.softdevice.s132v6.build.sd_fwid=0x00B7
# Debug Menu
ninab112.menu.debug.l0=Level 0 (Release)
ninab112.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
ninab112.menu.debug.l1=Level 1 (Error Message)
ninab112.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
ninab112.menu.debug.l2=Level 2 (Full Debug)
ninab112.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
ninab112.menu.debug.l3=Level 3 (Segger SystemView)
ninab112.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
ninab112.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1

View File

@ -0,0 +1,92 @@
/*
* Udp.cpp: Library to send/receive UDP packets.
*
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
* might not happen often in practice, but in larger network topologies, a UDP
* packet can be received out of sequence.
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
* aware of it. Again, this may not be a concern in practice on small local networks.
* For more information, see http://www.cafeaulait.org/course/week12/35.html
*
* MIT License:
* Copyright (c) 2008 Bjoern Hartmann
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* bjoern@cs.stanford.edu 12/30/2008
*/
#ifndef udp_h
#define udp_h
#include <Stream.h>
#include <IPAddress.h>
class UDP : public Stream {
public:
virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
virtual void stop() =0; // Finish with the UDP socket
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) =0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() =0;
// Write a single byte into the packet
virtual size_t write(uint8_t) =0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) =0;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() =0;
// Number of bytes remaining in the current packet
virtual int available() =0;
// Read a single byte from the current packet
virtual int read() =0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) =0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) =0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() =0;
virtual void flush() =0; // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() =0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() =0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
};
#endif

View File

@ -0,0 +1,164 @@
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
# Copyright (c) 2016 Sandeep Mistry All right reserved.
# Copyright (c) 2017 Adafruit Industries. All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
name=Adafruit nRF52 Boards
version=0.21.0
# Compile variables
# -----------------
compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall
compiler.warning_flags.all=-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-pointer-arith
# Allow changing optimization settings via platform.local.txt / boards.local.txt
compiler.optimization_flag=-Ofast
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
compiler.c.cmd=arm-none-eabi-gcc
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.warning_flags} {build.float_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD
# KH, Error here to use gcc, must use g++
#compiler.c.elf.cmd=arm-none-eabi-gcc
compiler.c.elf.cmd=arm-none-eabi-g++
compiler.c.elf.flags={compiler.optimization_flag} -Wl,--gc-sections -save-temps
compiler.S.cmd=arm-none-eabi-gcc
compiler.S.flags=-c -g -x assembler-with-cpp
compiler.cpp.cmd=arm-none-eabi-g++
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.warning_flags} {build.float_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD
compiler.ar.cmd=arm-none-eabi-ar
compiler.ar.flags=rcs
compiler.objcopy.cmd=arm-none-eabi-objcopy
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
compiler.elf2bin.flags=-O binary
compiler.elf2bin.cmd=arm-none-eabi-objcopy
compiler.elf2hex.flags=-O ihex
compiler.elf2hex.cmd=arm-none-eabi-objcopy
compiler.ldflags=-mcpu={build.mcu} -mthumb {build.float_flags} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align --specs=nano.specs --specs=nosys.specs
compiler.size.cmd=arm-none-eabi-size
# this can be overriden in boards.txt
build.float_flags=-mfloat-abi=hard -mfpu=fpv4-sp-d16 -u _printf_float
build.debug_flags=-DCFG_DEBUG=0
build.logger_flags=-DCFG_LOGGER=1
build.sysview_flags=-DCFG_SYSVIEW=0
# common compiler for nrf
rtos.path={build.core.path}/freertos
nordic.path={build.core.path}/nordic
# build.logger_flags and build.sysview_flags and intentionally empty,
# to allow modification via a user's own boards.local.txt or platform.local.txt files.
build.flags.nrf= -DSOFTDEVICE_PRESENT -DARDUINO_NRF52_ADAFRUIT -DNRF52_SERIES -DLFS_NAME_MAX=64 {compiler.optimization_flag} {build.debug_flags} {build.logger_flags} {build.sysview_flags} "-I{build.core.path}/cmsis/Core/Include" "-I{nordic.path}" "-I{nordic.path}/nrfx" "-I{nordic.path}/nrfx/hal" "-I{nordic.path}/nrfx/mdk" "-I{nordic.path}/nrfx/soc" "-I{nordic.path}/nrfx/drivers/include" "-I{nordic.path}/nrfx/drivers/src" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include/nrf52" "-I{rtos.path}/Source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52" "-I{build.core.path}/sysview/SEGGER" "-I{build.core.path}/sysview/Config" "-I{build.core.path}/TinyUSB" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src"
# usb flags
build.flags.usb= -DUSBCON -DUSE_TINYUSB -DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.cpp.extra_flags=
compiler.S.extra_flags=
compiler.ar.extra_flags=
compiler.libraries.ldflags=
compiler.elf2bin.extra_flags=
compiler.elf2hex.extra_flags=
# Compile patterns
# ----------------
## Compile c files
## KH Add -DBOARD_NAME="{build.board}"
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} '-DARDUINO_BSP_VERSION="{version}"' {compiler.c.extra_flags} {build.extra_flags} {build.flags.nrf} {includes} "{source_file}" -o "{object_file}"
## Compile c++ files
## KH Add -DBOARD_NAME="{build.board}"
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} '-DARDUINO_BSP_VERSION="{version}"' {compiler.cpp.extra_flags} {build.extra_flags} {build.flags.nrf} {includes} "{source_file}" -o "{object_file}"
## Compile S files
## KH Add -DBOARD_NAME="{build.board}"
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.flags.nrf} {includes} "{source_file}" -o "{object_file}"
## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-L{build.core.path}/linker" "-T{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} -Wl,--start-group -lm "{build.path}/{archive_file}" -Wl,--end-group
## Create output (bin file)
#recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2bin.cmd}" {compiler.elf2bin.flags} {compiler.elf2bin.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
## Create output (hex file)
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
## Create dfu package zip file
recipe.objcopy.zip.pattern="{tools.nrfutil.cmd}" dfu genpkg --dev-type 0x0052 --sd-req {build.sd_fwid} --application "{build.path}/{build.project_name}.hex" "{build.path}/{build.project_name}.zip"
## Create uf2 file
#recipe.objcopy.uf2.pattern=python "{runtime.platform.path}/tools/uf2conv/uf2conv.py" -f 0xADA52840 -c -o "{build.path}/{build.project_name}.uf2" "{build.path}/{build.project_name}.hex"
## Save bin
recipe.output.tmp_file_bin={build.project_name}.bin
recipe.output.save_file_bin={build.project_name}.save.bin
## Save hex
recipe.output.tmp_file_hex={build.project_name}.hex
recipe.output.save_file_hexu={build.project_name}.save.hex
## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=^(?:\.text|\.data|)\s+([0-9]+).*
recipe.size.regex.data=^(?:\.data|\.bss)\s+([0-9]+).*
## Export Compiled Binary
recipe.output.tmp_file={build.project_name}.hex
recipe.output.save_file={build.project_name}.{build.variant}.hex
#***************************************************
# adafruit-nrfutil for uploading
# https://github.com/adafruit/Adafruit_nRF52_nrfutil
# pre-built binaries are provided for macos and windows
#***************************************************
tools.nrfutil.cmd=adafruit-nrfutil
tools.nrfutil.cmd.windows={runtime.platform.path}/tools/adafruit-nrfutil/win32/adafruit-nrfutil.exe
tools.nrfutil.cmd.macosx={runtime.platform.path}/tools/adafruit-nrfutil/macos/adafruit-nrfutil
tools.nrfutil.upload.params.verbose=--verbose
tools.nrfutil.upload.params.quiet=
tools.nrfutil.upload.pattern="{cmd}" {upload.verbose} dfu serial -pkg "{build.path}/{build.project_name}.zip" -p {serial.port} -b 115200 --singlebank
#***************************************************
# Burning bootloader with either jlink or nrfutil
#***************************************************
# Bootloader version
tools.bootburn.bootloader.file={runtime.platform.path}/bootloader/{build.variant}/{build.variant}_bootloader-0.3.2_{build.sd_name}_{build.sd_version}
tools.bootburn.bootloader.params.verbose=
tools.bootburn.bootloader.params.quiet=
tools.bootburn.bootloader.pattern={program.burn_pattern}
# erase flash page while programming
tools.bootburn.erase.params.verbose=
tools.bootburn.erase.params.quiet=
tools.bootburn.erase.pattern=

View File

@ -0,0 +1,17 @@
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// API compatibility
#include "variant.h"

View File

@ -0,0 +1,62 @@
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Thanks to great work of [Miguel Alexandre Wisintainer](https://github.com/tcpipchip).
// See [u-blox nina b](https://github.com/khoih-prog/WiFiNINA_Generic/issues/1)
#include "variant.h"
#include "wiring_constants.h"
#include "wiring_digital.h"
#include "nrf.h"
const uint32_t g_ADigitalPinMap[] = {
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31
};

View File

@ -0,0 +1,173 @@
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _VARIANT_NINA_B112_UBLOX_
#define _VARIANT_NINA_B112_UBLOX_
#define NRF_CLOCK_LFCLKSRC {.source = NRF_CLOCK_LF_SRC_XTAL, \
.rc_ctiv = 0, \
.rc_temp_ctiv = 0, \
.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}
/** Master clock frequency */
#define VARIANT_MCK (64000000ul)
#define USE_LFXO // Board uses 32khz crystal for LF
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include "WVariant.h"
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
// Number of pins defined in PinDescription array
#define PINS_COUNT (32u)
#define NUM_DIGITAL_PINS (32u)
#define NUM_ANALOG_INPUTS (6u)
#define NUM_ANALOG_OUTPUTS (0u)
// LEDs
#define PIN_LED LED1
#define LED_BUILTIN PIN_LED
//LEDs onboard
#define LED1 (8) // Red
#define LED2 (16) // Green/SW1
#define LED3 (18) // Blue
#define LED_STATE_ON 1 // State when LED is litted
//Switch
#define SW1 (16)
#define SW2 (30)
// NFC
#define PIN_NFC_1 (9) // P0.9
#define PIN_NFC_2 (10) // P0.10
/*
* Analog pins
*/
#define PIN_A0 (3) // P0.03
#define PIN_A1 (2) // P0.02
#define PIN_A2 (4) // P0.04
#define PIN_A3 (30) // P0.30
#define PIN_A4 (29) // P0.29
#define PIN_A5 (28) // P0.28
static const uint8_t A0 = PIN_A0 ;
static const uint8_t A1 = PIN_A1 ;
static const uint8_t A2 = PIN_A2 ;
static const uint8_t A3 = PIN_A3 ;
static const uint8_t A4 = PIN_A4 ;
static const uint8_t A5 = PIN_A5 ;
#define ADC_RESOLUTION 14
#define PIN_D0 (5) // P0.05
#define PIN_D1 (6) // P0.06
#define PIN_D2 (7) // P0.07
#define PIN_D3 (31) // P0.31
#define PIN_D4 (18) // P0.18
#define PIN_D6 (9) // P0.09
#define PIN_D7 (10) // P0.10
#define PIN_D9 (8) // P0.8
#define PIN_D10 (11) // P0.11
#define PIN_D11 (13) // P0.13
#define PIN_D12 (12) // P0.12
#define PIN_D13 (14) // P0.14
#define PIN_D14 (2) // P0.02
#define PIN_D15 (3) // P0.03
static const uint8_t D0 = PIN_D0 ;
static const uint8_t D1 = PIN_D1 ;
static const uint8_t D2 = PIN_D2 ;
static const uint8_t D3 = PIN_D3 ;
static const uint8_t D4 = PIN_D4 ;
static const uint8_t D6 = PIN_D6 ;
static const uint8_t D7 = PIN_D7 ;
static const uint8_t D9 = PIN_D9 ;
static const uint8_t D10 = PIN_D10 ;
static const uint8_t D11 = PIN_D11 ;
static const uint8_t D12 = PIN_D12 ;
static const uint8_t D13 = PIN_D13 ;
static const uint8_t D14 = PIN_D14 ;
static const uint8_t D15 = PIN_D15 ;
// Other pins
//static const uint8_t AREF = PIN_AREF;
//#define PIN_AREF (24)
//#define PIN_VBAT PIN_A7
/*
* Serial interfaces
*/
//#define PIN_SERIAL_RX (8) //used for original Adafruit Bootloader
//#define PIN_SERIAL_TX (6) //used for original Adafruit Bootloader
#define PIN_SERIAL_RX (5) // P0.05
#define PIN_SERIAL_TX (6) // P0.06
#define PIN_SERIAL_CTS (7) // P0.07
#define PIN_SERIAL_RTS (31) // P0.31
#define PIN_SERIAL_DTR (28) // P0.28
#define PIN_SERIAL_DSR (29) // P0.29
/*
* SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (12) // P0.12
#define PIN_SPI_MOSI (13) // P0.13
#define PIN_SPI_SCK (14) // P0.14
static const uint8_t SS = 11 ; // P0.11
static const uint8_t MOSI = PIN_SPI_MOSI ;
static const uint8_t MISO = PIN_SPI_MISO ;
static const uint8_t SCK = PIN_SPI_SCK ;
/*
* Wire Interfaces
*/
#define WIRE_INTERFACES_COUNT 1
#define PIN_WIRE_SDA (2) // P0.02
#define PIN_WIRE_SCL (3) // P0.03
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
#ifdef __cplusplus
}
#endif
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
#endif //_VARIANT_NINA_B112_UBLOX_

View File

@ -0,0 +1,17 @@
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// API compatibility
#include "variant.h"

View File

@ -0,0 +1,109 @@
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Thanks to great work of [Miguel Alexandre Wisintainer](https://github.com/tcpipchip).
// See [u-blox nina b](https://github.com/khoih-prog/WiFiNINA_Generic/issues/1)
#include "variant.h"
#include "wiring_constants.h"
#include "wiring_digital.h"
#include "nrf.h"
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
29, // D0 is P0.29 (UART TX)
45, // D1 is P1.13 (UART RX
44, // D2 is P1.12 (NFC2)
31, // D3 is P0.31 (LED1)
13, // D4 is P0.13 (LED2)
11, // D5 is P0.11
9, // D6 is P0.09
10, // D7 is P0.10 (Button)
41, // D8 is P1.09 (NeoPixel)
12, // D9 is P0.12
14, // D10 is P0.14
15, // D11 is P0.15
32, // D12 is P1.00
7, // D13 is P0.07
// D14 .. D21 (aka A0 .. A7)
4, // D14 is P0.04 (A0)
30, // D15 is P0.30 (A1)
5, // D16 is P0.05 (A2)
2, // D17 is P0.02 (A3)
28, // D18 is P0.28 (A4)
3, // D19 is P0.03 (A5)
29, // D20 is P0.29 (A6, Battery) ????
31, // D21 is P0.31 (A7, ARef) ????
// D22 .. D23 (aka I2C pins)
16, // D22 is P0.16 (SDA)
24, // D23 is P0.24 (SCL)
// D24 .. D26 (aka SPI pins)
32, // D24 is P1.00 (SPI MISO)
15, // D25 is P0.15 (SPI MOSI)
7, // D26 is P0.07 (SPI SCK )
// QSPI pins (not exposed via any header / test point)
19, // D27 is P0.19 (QSPI CLK)
17, // D28 is P0.17 (QSPI CS)
20, // D29 is P0.20 (QSPI Data 0)
21, // D30 is P0.21 (QSPI Data 1)
22, // D31 is P0.22 (QSPI Data 2)
23, // D32 is P0.23 (QSPI Data 3)
// The remaining NFC pin
9, // D33 is P0.09 (NFC1, exposed only via test point on bottom of board)
// Thus, there are 34 defined pins
// The remaining pins are not usable:
//
//
// The following pins were never listed as they were considered unusable
// 0, // P0.00 is XL1 (attached to 32.768kHz crystal)
// 1, // P0.01 is XL2 (attached to 32.768kHz crystal)
// 18, // P0.18 is RESET (attached to switch)
// 32, // P1.00 is SWO (attached to debug header)
//
// The remaining pins are not connected (per schematic)
// 33, // P1.01 is not connected per schematic
// 35, // P1.03 is not connected per schematic
// 36, // P1.04 is not connected per schematic
// 37, // P1.05 is not connected per schematic
// 38, // P1.06 is not connected per schematic
// 39, // P1.07 is not connected per schematic
// 43, // P1.11 is not connected per schematic
// 44, // P1.12 is not connected per schematic
// 45, // P1.13 is not connected per schematic
// 46, // P1.14 is not connected per schematic
};
void initVariant()
{
// LED1 & LED2
pinMode(PIN_LED1, OUTPUT);
ledOff(PIN_LED1);
pinMode(PIN_LED2, OUTPUT);
ledOff(PIN_LED2);
}

View File

@ -0,0 +1,159 @@
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Thanks to great work of [Miguel Alexandre Wisintainer](https://github.com/tcpipchip).
// See [u-blox nina b](https://github.com/khoih-prog/WiFiNINA_Generic/issues/1)
#ifndef _VARIANT_NINA_B302_UBLOX_
#define _VARIANT_NINA_B302_UBLOX_
/** Master clock frequency */
#define VARIANT_MCK (64000000ul)
#define USE_LFXO // Board uses 32khz crystal for LF
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include "WVariant.h"
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
// (XX) = TABLE INDEX
// Number of pins defined in PinDescription array
#define PINS_COUNT (34)
#define NUM_DIGITAL_PINS (34)
#define NUM_ANALOG_INPUTS (6) // A6 is used for battery, A7 is analog reference
#define NUM_ANALOG_OUTPUTS (0)
// LEDs
#define PIN_LED1 (3)
#define PIN_LED2 (4)
#define PIN_NEOPIXEL (8)
#define LED_BUILTIN PIN_LED1
#define LED_CONN PIN_LED2
#define LED_RED PIN_LED1
#define LED_BLUE PIN_LED2
#define LED_STATE_ON 1 // State when LED is litted
/*
* Buttons
*/
#define PIN_BUTTON1 (7)
/*
* Analog pins
*/
#define PIN_A0 (14)
#define PIN_A1 (15)
#define PIN_A2 (16)
#define PIN_A3 (17)
#define PIN_A4 (18)
#define PIN_A5 (19)
#define PIN_A6 (20)
#define PIN_A7 (21)
#define D0 (0)
#define D1 (1)
#define D2 (2)
#define D3 (3)
#define D4 (4)
#define D5 (5)
#define D6 (6)
#define D7 (7)
#define D8 (8)
#define D9 (9)
#define D10 (10)
#define D11 (11)
#define D12 (12)
#define D13 (13)
static const uint8_t A0 = PIN_A0 ;
static const uint8_t A1 = PIN_A1 ;
static const uint8_t A2 = PIN_A2 ;
static const uint8_t A3 = PIN_A3 ;
static const uint8_t A4 = PIN_A4 ;
static const uint8_t A5 = PIN_A5 ;
static const uint8_t A6 = PIN_A6 ;
static const uint8_t A7 = PIN_A7 ;
#define ADC_RESOLUTION 14
// Other pins
#define PIN_AREF PIN_A7
#define PIN_VBAT PIN_A6
#define PIN_NFC1 (33)
#define PIN_NFC2 (2)
static const uint8_t AREF = PIN_AREF;
/*
* Serial interfaces
*/
#define PIN_SERIAL1_RX (1)
#define PIN_SERIAL1_TX (0)
/*
* SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (24) //24 original
#define PIN_SPI_MOSI (25) //25 original
#define PIN_SPI_SCK (26) //26 original
static const uint8_t SS = (13);
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
/*
* Wire Interfaces
*/
#define WIRE_INTERFACES_COUNT 1
#define PIN_WIRE_SDA (22)
#define PIN_WIRE_SCL (23)
// QSPI Pins
#define PIN_QSPI_SCK 27
#define PIN_QSPI_CS 28
#define PIN_QSPI_IO0 29
#define PIN_QSPI_IO1 30
#define PIN_QSPI_IO2 31
#define PIN_QSPI_IO3 32
// On-board QSPI Flash
#define EXTERNAL_FLASH_DEVICES GD25Q16C
#define EXTERNAL_FLASH_USE_QSPI
#ifdef __cplusplus
}
#endif
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
#endif //_VARIANT_NINA_B302_UBLOX_

View File

@ -0,0 +1,226 @@
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# Arduino SAMD Core and platform.
#
# For more info:
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
name=Adafruit SAMD (32-bits ARM Cortex-M0+ and Cortex-M4) Boards
version=1.6.3
# Compile variables
# -----------------
compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall -Wno-expansion-to-defined
compiler.warning_flags.all=-Wall -Wextra -Wno-expansion-to-defined
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
compiler.c.cmd=arm-none-eabi-gcc
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -D__SKETCH_NAME__="""{build.project_name}"""
compiler.c.elf.cmd=arm-none-eabi-g++
compiler.c.elf.flags=-Os -Wl,--gc-sections -save-temps
compiler.S.cmd=arm-none-eabi-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
compiler.cpp.cmd=arm-none-eabi-g++
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -D__SKETCH_NAME__="""{build.project_name}"""
compiler.ar.cmd=arm-none-eabi-ar
compiler.ar.flags=rcs
compiler.objcopy.cmd=arm-none-eabi-objcopy
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
compiler.elf2hex.bin.flags=-O binary
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
compiler.elf2hex.cmd=arm-none-eabi-objcopy
compiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align
compiler.size.cmd=arm-none-eabi-size
compiler.define=-DARDUINO=
compiler.readelf.cmd=arm-none-eabi-readelf
# this can be overriden in boards.txt
build.extra_flags=
build.cache_flags=
build.flags.optimize=
build.flags.maxspi=
build.flags.maxqspi=
build.flags.usbstack=
build.flags.debug=
# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
#compiler.c.elf.extra_flags=-v
compiler.cpp.extra_flags=
compiler.S.extra_flags=
compiler.ar.extra_flags=
compiler.elf2hex.extra_flags=
compiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-5.4.0.path}/CMSIS/Core/Include/" "-I{runtime.tools.CMSIS-5.4.0.path}/CMSIS/DSP/Include/" "-I{runtime.tools.CMSIS-Atmel-1.2.0.path}/CMSIS/Device/ATMEL/"
compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-5.4.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
compiler.libraries.ldflags=
# USB Flags
# ---------
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON -DUSB_CONFIG_POWER={build.usb_power} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' {build.flags.usbstack} {build.flags.debug} "-I{build.core.path}/TinyUSB" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src"
# Default advertised device power setting in mA
build.usb_power=100
# Default usb manufacturer will be replaced at compile time using
# numeric vendor ID if available or by board's specific value.
build.usb_manufacturer="Unknown"
# Compile patterns
# ----------------
## Compile c files
## KH Add -DBOARD_NAME="{build.board}"
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.cache_flags} {build.flags.debug} {build.flags.optimize} {build.flags.maxspi} {build.flags.maxqspi} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
## Compile c++ files
## KH Add -DBOARD_NAME="{build.board}"
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.cache_flags} {build.flags.debug} {build.flags.optimize} {build.flags.maxspi} {build.flags.maxqspi} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
## Compile S files
## KH Add -DBOARD_NAME="{build.board}"
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.cache_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
## Create archives
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
archive_file_path={build.path}/{archive_file}
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} -Wl,--start-group {compiler.arm.cmsis.ldflags} "-L{build.variant.path}" -lm "{build.path}/{archive_file}" -Wl,--end-group
## Create output (bin file)
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.bin.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
## Create output (hex file)
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
build.preferred_out_format=bin
## Save hex
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=\.text\s+([0-9]+).*
#
# BOSSA
#
tools.bossac.path={runtime.tools.bossac-1.7.0-arduino3.path}
tools.bossac.cmd=bossac
tools.bossac.cmd.windows=bossac.exe
tools.bossac.upload.params.verbose=-i -d
tools.bossac.upload.params.quiet=
tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -i -e -w -v "{build.path}/{build.project_name}.bin" -R
tools.bossac_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
tools.bossac.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
tools.bossac.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
# v1.8.0
tools.bossac18.path={runtime.tools.bossac-1.8.0-48-gb176eee.path}
tools.bossac18.cmd=bossac
tools.bossac18.upload.params.verbose=-i -d
tools.bossac18.upload.params.quiet=
tools.bossac18.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U -i --offset={upload.offset} -w -v "{build.path}/{build.project_name}.bin" -R
tools.bossac18.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
tools.bossac18.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
#
# BOSSA (ignore binary size)
#
tools.bossacI.path={runtime.tools.bossac-1.7.0-arduino3.path}
tools.bossacI.cmd=bossac
tools.bossacI.cmd.windows=bossac.exe
tools.bossacI.upload.params.verbose=-i -d
tools.bossacI.upload.params.quiet=
tools.bossacI.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -I -U {upload.native_usb} -i -e -w "{build.path}/{build.project_name}.bin" -R
tools.bossacI_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
tools.bossacI.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
tools.bossacI.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
#
# OpenOCD sketch upload
#
tools.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}
tools.openocd.cmd=bin/openocd
tools.openocd.cmd.windows=bin/openocd.exe
tools.openocd.upload.params.verbose=-d2
tools.openocd.upload.params.quiet=-d0
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset 0x2000; shutdown"
tools.openocd.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
tools.openocd.upload.network_pattern={network_cmd} -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
tools.openocd.program.params.verbose=-d2
tools.openocd.program.params.quiet=-d0
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
tools.openocd.erase.params.verbose=-d3
tools.openocd.erase.params.quiet=-d0
tools.openocd.erase.pattern=
tools.openocd.bootloader.params.verbose=-d2
tools.openocd.bootloader.params.quiet=-d0
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
#
# OpenOCD sketch upload - version with configurable bootloader size
# FIXME: this programmer is a workaround for default options being overwritten by uploadUsingPreferences
#
tools.openocd-withbootsize.path={runtime.tools.openocd-0.10.0-arduino7.path}
tools.openocd-withbootsize.cmd=bin/openocd
tools.openocd-withbootsize.cmd.windows=bin/openocd.exe
tools.openocd-withbootsize.upload.params.verbose=-d2
tools.openocd-withbootsize.upload.params.quiet=-d0
tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
tools.openocd-withbootsize.program.params.verbose=-d2
tools.openocd-withbootsize.program.params.quiet=-d0
tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
tools.openocd-withbootsize.erase.params.verbose=-d3
tools.openocd-withbootsize.erase.params.quiet=-d0
tools.openocd-withbootsize.erase.pattern=
tools.openocd-withbootsize.bootloader.params.verbose=-d2
tools.openocd-withbootsize.bootloader.params.quiet=-d0
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"

View File

@ -47,7 +47,7 @@ Chunked responses are recognized and handled transparently.
### Releases v1.0.0
1. Initial coding to add support to STM32F/L/H/G/WB/MP1 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
1. Initial coding to add support to **STM32F/L/H/G/WB/MP1** using built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc).
2. Add examples using STM32 boards.
#### Currently Supported Boards
@ -67,12 +67,14 @@ Chunked responses are recognized and handled transparently.
This library is based on, modified from:
1. [Bob Lemaire's asyncHTTPrequest Library](https://github.com/boblemaire/asyncHTTPrequest)
---
---
## Prerequisite
1. [`Arduino IDE 1.8.12+` for Arduino](https://www.arduino.cc/en/Main/Software)
2. [`ESP8266 Core 2.7.3+`](https://github.com/esp8266/Arduino) for ESP8266-based boards.
1. [`Arduino IDE 1.8.13+` for Arduino](https://www.arduino.cc/en/Main/Software)
2. [`ESP8266 Core 2.7.4+`](https://github.com/esp8266/Arduino) for ESP8266-based boards.
3. [`ESP32 Core 1.0.4+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards
4. [`Arduino Core for STM32 1.9.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for for STM32 using built-in Ethernet LAN8742A.
5. [`ESPAsyncTCP v1.2.2+`](https://github.com/me-no-dev/ESPAsyncTCP) for ESP8266.
@ -106,16 +108,16 @@ The best and easiest way is to use `Arduino Library Manager`. Search for `AsyncH
### Packages' Patches
1. ***To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards***, you have to copy the whole [nRF52 0.20.5](Packages_Patches/adafruit/hardware/nrf52/0.20.5) directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/0.20.5).
1. ***To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards***, you have to copy the whole [nRF52 0.21.0](Packages_Patches/adafruit/hardware/nrf52/0.21.0) directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0).
Supposing the Adafruit nRF52 version is 0.20.5. These files must be copied into the directory:
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.20.5/platform.txt`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.20.5/boards.txt`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.20.5/variants/NINA_B302_ublox/variant.h`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.20.5/variants/NINA_B302_ublox/variant.cpp`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.20.5/variants/NINA_B112_ublox/variant.h`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.20.5/variants/NINA_B112_ublox/variant.cpp`
- ***`~/.arduino15/packages/adafruit/hardware/nrf52/0.20.5/cores/nRF5/Udp.h`***
Supposing the Adafruit nRF52 version is 0.21.0. These files must be copied into the directory:
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/platform.txt`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/boards.txt`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/variants/NINA_B302_ublox/variant.h`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/variants/NINA_B302_ublox/variant.cpp`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/variants/NINA_B112_ublox/variant.h`
- `~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/variants/NINA_B112_ublox/variant.cpp`
- ***`~/.arduino15/packages/adafruit/hardware/nrf52/0.21.0/cores/nRF5/Udp.h`***
Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z
These files must be copied into the directory:
@ -172,22 +174,22 @@ These files must be copied into the directory:
Whenever the above-mentioned compiler error issue is fixed with the new Arduino SAMD release, you don't need to copy the `Arduino.h` file anymore.
5. ***To be able to automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the file [Adafruit SAMD platform.txt](Packages_Patches/adafruit/hardware/samd/1.6.0) into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.6.0).
5. ***To be able to automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the file [Adafruit SAMD platform.txt](Packages_Patches/adafruit/hardware/samd/1.6.3) into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.6.3).
Supposing the Adafruit SAMD core version is 1.6.0. This file must be copied into the directory:
Supposing the Adafruit SAMD core version is 1.6.3. This file must be copied into the directory:
- `~/.arduino15/packages/adafruit/hardware/samd/1.6.0/platform.txt`
- `~/.arduino15/packages/adafruit/hardware/samd/1.6.3/platform.txt`
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
- `~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/platform.txt`
6. ***To be able to automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the file [Seeeduino SAMD platform.txt](Packages_Patches/Seeeduino/hardware/samd/1.7.8) into Adafruit samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.7.8).
6. ***To be able to automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the file [Seeeduino SAMD platform.txt](Packages_Patches/Seeeduino/hardware/samd/1.7.9) into Adafruit samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.7.9).
Supposing the Seeeduino SAMD core version is 1.7.8. This file must be copied into the directory:
Supposing the Seeeduino SAMD core version is 1.7.9. This file must be copied into the directory:
- `~/.arduino15/packages/Seeeduino/hardware/samd/1.7.8/platform.txt`
- `~/.arduino15/packages/Seeeduino/hardware/samd/1.7.9/platform.txt`
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
@ -216,6 +218,11 @@ Also see examples:
1. [AsyncHTTPRequest_ESP](examples/AsyncHTTPRequest_ESP)
2. [AsyncHTTPRequest_ESP_WiFiManager](examples/AsyncHTTPRequest_ESP_WiFiManager)
3. [AsyncHTTPRequest_STM32](examples/AsyncHTTPRequest_STM32)
4. [AsyncCustomHeader_STM32](examples/AsyncCustomHeader_STM32)
5. [AsyncDweetGet_STM32](examples/AsyncDweetGet_STM32)
6. [AsyncDweetPost_STM32](examples/AsyncDweetPost_STM32)
7. [AsyncSimpleGET_STM32](examples/AsyncSimpleGET_STM32)
8. [AsyncWebClientRepeating_STM32](examples/AsyncWebClientRepeating_STM32)
---
@ -581,6 +588,60 @@ week_number: 37
HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H
```
---
#### 5. [AsyncWebClientRepeating_STM32](examples/AsyncWebClientRepeating_STM32) running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A
```
Start AsyncWebClientRepeating_STM32 on NUCLEO_F767ZI
AsyncHTTPRequest @ IP : 192.168.2.72
**************************************
`:;;;,` .:;;:.
.;;;;;;;;;;;` :;;;;;;;;;;: TM
`;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;;
:;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;;
;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;;
.;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;;
;;;;;; ;;;;;;; ;;;;;;, ;;;;;;.
,;;;;; ;;;;;;.;;;;;;` ;;;;;;
;;;;;. ;;;;;;;;;;;` ``` ;;;;;`
;;;;; ;;;;;;;;;, ;;; .;;;;;
`;;;;: `;;;;;;;; ;;; ;;;;;
,;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;
:;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;
:;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;
.;;;;. ;;;;;;;. ;;; ;;;;;
;;;;; ;;;;;;;;; ;;; ;;;;;
;;;;; .;;;;;;;;;; ;;; ;;;;;,
;;;;;; `;;;;;;;;;;;; ;;;;;
`;;;;;, .;;;;;; ;;;;;;; ;;;;;;
;;;;;;: :;;;;;;. ;;;;;;; ;;;;;;
;;;;;;;` .;;;;;;;, ;;;;;;;; ;;;;;;;:
;;;;;;;;;:,:;;;;;;;;;: ;;;;;;;;;;:,;;;;;;;;;;
`;;;;;;;;;;;;;;;;;;;. ;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;:
,;;;;;;;;;;;;;, ;;;;;;;;;;;;;;
.;;;;;;;;;` ,;;;;;;;;:
;;; ;;;;;` ;;;;: .;; ;; ,;;;;;, ;;. `;, ;;;;
;;; ;;:;;; ;;;;;; .;; ;; ,;;;;;: ;;; `;, ;;;:;;
,;:; ;; ;; ;; ;; .;; ;; ,;, ;;;,`;, ;; ;;
;; ;: ;; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;.
;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;`
,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;;
;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;;
;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;;
```
---
---
@ -631,7 +692,7 @@ Submit issues to: [AsyncHTTPRequest_Generic issues](https://github.com/khoih-pro
### Releases v1.0.0
1. Initial coding to add support to STM32F/L/H/G/WB/MP1 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
1. Initial coding to add support to **STM32F/L/H/G/WB/MP1** using built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc).
2. Add examples using STM32 boards.
---

View File

@ -0,0 +1,108 @@
/****************************************************************************************************************************
AsyncCustomHeader_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
#include "defines.h"
// Select a test server address
char GET_ServerAddress[] = "192.168.2.110/";
//char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";
// 600s = 10 minutes to not flooding
#define HTTP_REQUEST_INTERVAL_MS 600000
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
#include <Ticker.h> // https://github.com/sstaub/Ticker
AsyncHTTPRequest request;
void sendRequest(void);
// Repeat forever, millis() resolution
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
request.open("GET", GET_ServerAddress);
request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
request.send();
}
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
{
if (readyState == readyStateDone)
{
Serial.println("\n**************************************");
Serial.println(request->responseText());
Serial.println("**************************************");
request->setDebug(false);
}
}
void setup(void)
{
Serial.begin(115200);
while (!Serial);
Serial.println("\nStart AsyncCustomHeader_STM32 on " + String(BOARD_NAME));
// start the ethernet connection and the server
// Use random mac
uint16_t index = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[index], ip);
// Use DHCP dynamic IP and random mac
Ethernet.begin(mac[index]);
Serial.print(F("AsyncHTTPRequest @ IP : "));
Serial.println(Ethernet.localIP());
Serial.println();
request.setDebug(false);
// 5s timeout
request.setTimeout(5);
request.onReadyStateChange(requestCB);
sendHTTPRequest.start(); //start the ticker.
// Send first request now
delay(10000);
sendRequest();
}
void loop(void)
{
sendHTTPRequest.update();
}

View File

@ -0,0 +1,140 @@
/****************************************************************************************************************************
defines.h
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
/*
Currently support
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
- Nucleo-144 (F429ZI, F767ZI)
- Discovery (STM32F746G-DISCOVERY)
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
*/
#ifndef defines_h
#define defines_h
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
#endif
#define ASYNC_HTTP_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_HTTP_LOGLEVEL_ 1
#if defined(STM32F0)
#warning STM32F0 board selected
#define BOARD_TYPE "STM32F0"
#elif defined(STM32F1)
#warning STM32F1 board selected
#define BOARD_TYPE "STM32F1"
#elif defined(STM32F2)
#warning STM32F2 board selected
#define BOARD_TYPE "STM32F2"
#elif defined(STM32F3)
#warning STM32F3 board selected
#define BOARD_TYPE "STM32F3"
#elif defined(STM32F4)
#warning STM32F4 board selected
#define BOARD_TYPE "STM32F4"
#elif defined(STM32F7)
#warning STM32F7 board selected
#define BOARD_TYPE "STM32F7"
#elif defined(STM32L0)
#warning STM32L0 board selected
#define BOARD_TYPE "STM32L0"
#elif defined(STM32L1)
#warning STM32L1 board selected
#define BOARD_TYPE "STM32L1"
#elif defined(STM32L4)
#warning STM32L4 board selected
#define BOARD_TYPE "STM32L4"
#elif defined(STM32H7)
#warning STM32H7 board selected
#define BOARD_TYPE "STM32H7"
#elif defined(STM32G0)
#warning STM32G0 board selected
#define BOARD_TYPE "STM32G0"
#elif defined(STM32G4)
#warning STM32G4 board selected
#define BOARD_TYPE "STM32G4"
#elif defined(STM32WB)
#warning STM32WB board selected
#define BOARD_TYPE "STM32WB"
#elif defined(STM32MP1)
#warning STM32MP1 board selected
#define BOARD_TYPE "STM32MP1"
#else
#warning STM32 unknown board selected
#define BOARD_TYPE "STM32 Unknown"
#endif
#ifndef BOARD_NAME
#define BOARD_NAME BOARD_TYPE
#endif
#include <LwIP.h>
#include <STM32Ethernet.h>
//#include <AsyncUDP_STM32.h>
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
};
// Select the static IP address according to your local network
IPAddress ip(192, 168, 2, 232);
#endif //defines_h

View File

@ -0,0 +1,147 @@
/****************************************************************************************************************************
AsyncDweetGET_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
/**
Connects to dweet.io once every 1 minutes, sends a GET request and a request body.
Shows how to use Strings to assemble path and parse content from response.
dweet.io expects: https://dweet.io/dweet/for/thingName
For more on dweet.io, see https://dweet.io/play/
* */
#include "defines.h"
// Select a test server address
const char GET_ServerAddress[] = "dweet.io";
// use your own thing name here
String dweetName = "/dweet/for/currentSecond?second=";
// 10s = 10 seconds to not flooding the server
#define HTTP_REQUEST_INTERVAL_MS 10000
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
#include <Ticker.h> // https://github.com/sstaub/Ticker
AsyncHTTPRequest request;
void sendRequest(void);
// Repeat forever, millis() resolution
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
request.open("GET", (GET_ServerAddress + dweetName + String(millis()/1000)).c_str() );
request.send();
}
}
void parseResponse(String responseText)
{
/*
Typical response is:
{"this":"succeeded",
"by":"getting",
"the":"dweets",
"with":[{"thing":"my-thing-name",
"created":"2016-02-16T05:10:36.589Z",
"content":{"sensorValue":456}}]}
You want "content": numberValue
*/
// now parse the response looking for "content":
int labelStart = responseText.indexOf("content\":");
// find the first { after "content":
int contentStart = responseText.indexOf("{", labelStart);
// find the following } and get what's between the braces:
int contentEnd = responseText.indexOf("}", labelStart);
String content = responseText.substring(contentStart + 1, contentEnd);
Serial.println(content);
// now get the value after the colon, and convert to an int:
int valueStart = content.indexOf(":");
String valueString = content.substring(valueStart + 1);
int number = valueString.toInt();
Serial.print("Value string: ");
Serial.println(valueString);
Serial.print("Actual value: ");
Serial.println(number);
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
{
if (readyState == readyStateDone)
{
String responseText = request->responseText();
Serial.println("\n**************************************");
//Serial.println(request->responseText());
Serial.println(responseText);
Serial.println("**************************************");
parseResponse(responseText);
request->setDebug(false);
}
}
void setup(void)
{
Serial.begin(115200);
while (!Serial);
Serial.println("\nStart AsyncDweetGET_STM32 on " + String(BOARD_NAME));
// start the ethernet connection and the server
// Use random mac
uint16_t index = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[index], ip);
// Use DHCP dynamic IP and random mac
Ethernet.begin(mac[index]);
Serial.print(F("AsyncHTTPRequest @ IP : "));
Serial.println(Ethernet.localIP());
Serial.println();
request.setDebug(false);
request.onReadyStateChange(requestCB);
sendHTTPRequest.start(); //start the ticker.
}
void loop(void)
{
sendHTTPRequest.update();
}

View File

@ -0,0 +1,140 @@
/****************************************************************************************************************************
defines.h
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
/*
Currently support
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
- Nucleo-144 (F429ZI, F767ZI)
- Discovery (STM32F746G-DISCOVERY)
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
*/
#ifndef defines_h
#define defines_h
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
#endif
#define ASYNC_HTTP_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_HTTP_LOGLEVEL_ 1
#if defined(STM32F0)
#warning STM32F0 board selected
#define BOARD_TYPE "STM32F0"
#elif defined(STM32F1)
#warning STM32F1 board selected
#define BOARD_TYPE "STM32F1"
#elif defined(STM32F2)
#warning STM32F2 board selected
#define BOARD_TYPE "STM32F2"
#elif defined(STM32F3)
#warning STM32F3 board selected
#define BOARD_TYPE "STM32F3"
#elif defined(STM32F4)
#warning STM32F4 board selected
#define BOARD_TYPE "STM32F4"
#elif defined(STM32F7)
#warning STM32F7 board selected
#define BOARD_TYPE "STM32F7"
#elif defined(STM32L0)
#warning STM32L0 board selected
#define BOARD_TYPE "STM32L0"
#elif defined(STM32L1)
#warning STM32L1 board selected
#define BOARD_TYPE "STM32L1"
#elif defined(STM32L4)
#warning STM32L4 board selected
#define BOARD_TYPE "STM32L4"
#elif defined(STM32H7)
#warning STM32H7 board selected
#define BOARD_TYPE "STM32H7"
#elif defined(STM32G0)
#warning STM32G0 board selected
#define BOARD_TYPE "STM32G0"
#elif defined(STM32G4)
#warning STM32G4 board selected
#define BOARD_TYPE "STM32G4"
#elif defined(STM32WB)
#warning STM32WB board selected
#define BOARD_TYPE "STM32WB"
#elif defined(STM32MP1)
#warning STM32MP1 board selected
#define BOARD_TYPE "STM32MP1"
#else
#warning STM32 unknown board selected
#define BOARD_TYPE "STM32 Unknown"
#endif
#ifndef BOARD_NAME
#define BOARD_NAME BOARD_TYPE
#endif
#include <LwIP.h>
#include <STM32Ethernet.h>
//#include <AsyncUDP_STM32.h>
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
};
// Select the static IP address according to your local network
IPAddress ip(192, 168, 2, 232);
#endif //defines_h

View File

@ -0,0 +1,146 @@
/****************************************************************************************************************************
AsyncDweetPOST_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
// Dweet.io POST client. Connects to dweet.io once every ten seconds, sends a POST request and a request body.
// Shows how to use Strings to assemble path and body
#include "defines.h"
// Select a test server address
const char POST_ServerAddress[] = "dweet.io";
// use your own thing name here
String dweetName = "/dweet/for/pinA0-Read?";
// 10s = 10 seconds to not flooding the server
#define HTTP_REQUEST_INTERVAL_MS 10000
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
#include <Ticker.h> // https://github.com/sstaub/Ticker
AsyncHTTPRequest request;
void sendRequest(void);
// Repeat forever, millis() resolution
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
String postData = "sensorValue=";
postData += analogRead(A0);
Serial.println("\nMaking new POST request");
request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
request.send();
}
}
void parseResponse(String responseText)
{
/*
Typical response is:
{"this":"succeeded",
"by":"getting",
"the":"dweets",
"with":[{"thing":"my-thing-name",
"created":"2016-02-16T05:10:36.589Z",
"content":{"sensorValue":456}}]}
You want "content": numberValue
*/
// now parse the response looking for "content":
int labelStart = responseText.indexOf("content\":");
// find the first { after "content":
int contentStart = responseText.indexOf("{", labelStart);
// find the following } and get what's between the braces:
int contentEnd = responseText.indexOf("}", labelStart);
String content = responseText.substring(contentStart + 1, contentEnd);
Serial.println(content);
// now get the value after the colon, and convert to an int:
int valueStart = content.indexOf(":");
String valueString = content.substring(valueStart + 1);
int number = valueString.toInt();
Serial.print("Value string: ");
Serial.println(valueString);
Serial.print("Actual value: ");
Serial.println(number);
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
{
if (readyState == readyStateDone)
{
String responseText = request->responseText();
Serial.println("\n**************************************");
//Serial.println(request->responseText());
Serial.println(responseText);
Serial.println("**************************************");
parseResponse(responseText);
request->setDebug(false);
}
}
void setup(void)
{
Serial.begin(115200);
while (!Serial);
Serial.println("\nStart AsyncDweetPOST_STM32 on " + String(BOARD_NAME));
// start the ethernet connection and the server
// Use random mac
uint16_t index = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[index], ip);
// Use DHCP dynamic IP and random mac
Ethernet.begin(mac[index]);
Serial.print(F("AsyncHTTPRequest @ IP : "));
Serial.println(Ethernet.localIP());
Serial.println();
request.setDebug(false);
request.onReadyStateChange(requestCB);
sendHTTPRequest.start(); //start the ticker.
}
void loop(void)
{
sendHTTPRequest.update();
}

View File

@ -0,0 +1,140 @@
/****************************************************************************************************************************
defines.h
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
/*
Currently support
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
- Nucleo-144 (F429ZI, F767ZI)
- Discovery (STM32F746G-DISCOVERY)
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
*/
#ifndef defines_h
#define defines_h
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
#endif
#define ASYNC_HTTP_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_HTTP_LOGLEVEL_ 1
#if defined(STM32F0)
#warning STM32F0 board selected
#define BOARD_TYPE "STM32F0"
#elif defined(STM32F1)
#warning STM32F1 board selected
#define BOARD_TYPE "STM32F1"
#elif defined(STM32F2)
#warning STM32F2 board selected
#define BOARD_TYPE "STM32F2"
#elif defined(STM32F3)
#warning STM32F3 board selected
#define BOARD_TYPE "STM32F3"
#elif defined(STM32F4)
#warning STM32F4 board selected
#define BOARD_TYPE "STM32F4"
#elif defined(STM32F7)
#warning STM32F7 board selected
#define BOARD_TYPE "STM32F7"
#elif defined(STM32L0)
#warning STM32L0 board selected
#define BOARD_TYPE "STM32L0"
#elif defined(STM32L1)
#warning STM32L1 board selected
#define BOARD_TYPE "STM32L1"
#elif defined(STM32L4)
#warning STM32L4 board selected
#define BOARD_TYPE "STM32L4"
#elif defined(STM32H7)
#warning STM32H7 board selected
#define BOARD_TYPE "STM32H7"
#elif defined(STM32G0)
#warning STM32G0 board selected
#define BOARD_TYPE "STM32G0"
#elif defined(STM32G4)
#warning STM32G4 board selected
#define BOARD_TYPE "STM32G4"
#elif defined(STM32WB)
#warning STM32WB board selected
#define BOARD_TYPE "STM32WB"
#elif defined(STM32MP1)
#warning STM32MP1 board selected
#define BOARD_TYPE "STM32MP1"
#else
#warning STM32 unknown board selected
#define BOARD_TYPE "STM32 Unknown"
#endif
#ifndef BOARD_NAME
#define BOARD_NAME BOARD_TYPE
#endif
#include <LwIP.h>
#include <STM32Ethernet.h>
//#include <AsyncUDP_STM32.h>
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
};
// Select the static IP address according to your local network
IPAddress ip(192, 168, 2, 232);
#endif //defines_h

View File

@ -0,0 +1,101 @@
/****************************************************************************************************************************
AsyncSimpleGET_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
#include "defines.h"
// Select a test server address
//char GET_ServerAddress[] = "ipv4bot.whatismyipaddress.com/";
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";
// 600s = 10 minutes to not flooding
#define HTTP_REQUEST_INTERVAL_MS 600000
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
#include <Ticker.h> // https://github.com/sstaub/Ticker
AsyncHTTPRequest request;
void sendRequest(void);
// Repeat forever, millis() resolution
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
request.open("GET", GET_ServerAddress);
request.send();
}
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
{
if (readyState == readyStateDone)
{
Serial.println("\n**************************************");
Serial.println(request->responseText());
Serial.println("**************************************");
request->setDebug(false);
}
}
void setup(void)
{
Serial.begin(115200);
while (!Serial);
Serial.println("\nStart AsyncSimpleGET_STM32 on " + String(BOARD_NAME));
// start the ethernet connection and the server
// Use random mac
uint16_t index = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[index], ip);
// Use DHCP dynamic IP and random mac
Ethernet.begin(mac[index]);
Serial.print(F("AsyncHTTPRequest @ IP : "));
Serial.println(Ethernet.localIP());
Serial.println();
request.setDebug(false);
request.onReadyStateChange(requestCB);
sendHTTPRequest.start(); //start the ticker.
// Send first request now
delay(10000);
sendRequest();
}
void loop(void)
{
sendHTTPRequest.update();
}

View File

@ -0,0 +1,140 @@
/****************************************************************************************************************************
defines.h
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
/*
Currently support
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
- Nucleo-144 (F429ZI, F767ZI)
- Discovery (STM32F746G-DISCOVERY)
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
*/
#ifndef defines_h
#define defines_h
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
#endif
#define ASYNC_HTTP_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_HTTP_LOGLEVEL_ 1
#if defined(STM32F0)
#warning STM32F0 board selected
#define BOARD_TYPE "STM32F0"
#elif defined(STM32F1)
#warning STM32F1 board selected
#define BOARD_TYPE "STM32F1"
#elif defined(STM32F2)
#warning STM32F2 board selected
#define BOARD_TYPE "STM32F2"
#elif defined(STM32F3)
#warning STM32F3 board selected
#define BOARD_TYPE "STM32F3"
#elif defined(STM32F4)
#warning STM32F4 board selected
#define BOARD_TYPE "STM32F4"
#elif defined(STM32F7)
#warning STM32F7 board selected
#define BOARD_TYPE "STM32F7"
#elif defined(STM32L0)
#warning STM32L0 board selected
#define BOARD_TYPE "STM32L0"
#elif defined(STM32L1)
#warning STM32L1 board selected
#define BOARD_TYPE "STM32L1"
#elif defined(STM32L4)
#warning STM32L4 board selected
#define BOARD_TYPE "STM32L4"
#elif defined(STM32H7)
#warning STM32H7 board selected
#define BOARD_TYPE "STM32H7"
#elif defined(STM32G0)
#warning STM32G0 board selected
#define BOARD_TYPE "STM32G0"
#elif defined(STM32G4)
#warning STM32G4 board selected
#define BOARD_TYPE "STM32G4"
#elif defined(STM32WB)
#warning STM32WB board selected
#define BOARD_TYPE "STM32WB"
#elif defined(STM32MP1)
#warning STM32MP1 board selected
#define BOARD_TYPE "STM32MP1"
#else
#warning STM32 unknown board selected
#define BOARD_TYPE "STM32 Unknown"
#endif
#ifndef BOARD_NAME
#define BOARD_NAME BOARD_TYPE
#endif
#include <LwIP.h>
#include <STM32Ethernet.h>
//#include <AsyncUDP_STM32.h>
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
};
// Select the static IP address according to your local network
IPAddress ip(192, 168, 2, 232);
#endif //defines_h

View File

@ -0,0 +1,103 @@
/****************************************************************************************************************************
AsyncWebClientRepeating_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
#include "defines.h"
// Select a test server address
const char GET_ServerAddress[] = "arduino.cc";
// GET location
String GET_Location = "/asciilogo.txt";
// 10s = 10 seconds to not flooding the server
#define HTTP_REQUEST_INTERVAL_MS 10000
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
#include <Ticker.h> // https://github.com/sstaub/Ticker
AsyncHTTPRequest request;
void sendRequest(void);
// Repeat forever, millis() resolution
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
void sendRequest(void)
{
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
request.open("GET", (GET_ServerAddress + GET_Location).c_str());
request.send();
}
}
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
{
if (readyState == readyStateDone)
{
Serial.println("\n**************************************");
Serial.println(request->responseText());
Serial.println("**************************************");
request->setDebug(false);
}
}
void setup(void)
{
Serial.begin(115200);
while (!Serial);
Serial.println("\nStart AsyncWebClientRepeating_STM32 on " + String(BOARD_NAME));
// start the ethernet connection and the server
// Use random mac
uint16_t index = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[index], ip);
// Use DHCP dynamic IP and random mac
Ethernet.begin(mac[index]);
Serial.print(F("AsyncHTTPRequest @ IP : "));
Serial.println(Ethernet.localIP());
Serial.println();
request.setDebug(false);
request.onReadyStateChange(requestCB);
sendHTTPRequest.start(); //start the ticker
// Send first request now
sendRequest();
}
void loop(void)
{
sendHTTPRequest.update();
}

View File

@ -0,0 +1,140 @@
/****************************************************************************************************************************
defines.h
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
/*
Currently support
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
- Nucleo-144 (F429ZI, F767ZI)
- Discovery (STM32F746G-DISCOVERY)
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
*/
#ifndef defines_h
#define defines_h
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
#endif
#define ASYNC_HTTP_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_HTTP_LOGLEVEL_ 1
#if defined(STM32F0)
#warning STM32F0 board selected
#define BOARD_TYPE "STM32F0"
#elif defined(STM32F1)
#warning STM32F1 board selected
#define BOARD_TYPE "STM32F1"
#elif defined(STM32F2)
#warning STM32F2 board selected
#define BOARD_TYPE "STM32F2"
#elif defined(STM32F3)
#warning STM32F3 board selected
#define BOARD_TYPE "STM32F3"
#elif defined(STM32F4)
#warning STM32F4 board selected
#define BOARD_TYPE "STM32F4"
#elif defined(STM32F7)
#warning STM32F7 board selected
#define BOARD_TYPE "STM32F7"
#elif defined(STM32L0)
#warning STM32L0 board selected
#define BOARD_TYPE "STM32L0"
#elif defined(STM32L1)
#warning STM32L1 board selected
#define BOARD_TYPE "STM32L1"
#elif defined(STM32L4)
#warning STM32L4 board selected
#define BOARD_TYPE "STM32L4"
#elif defined(STM32H7)
#warning STM32H7 board selected
#define BOARD_TYPE "STM32H7"
#elif defined(STM32G0)
#warning STM32G0 board selected
#define BOARD_TYPE "STM32G0"
#elif defined(STM32G4)
#warning STM32G4 board selected
#define BOARD_TYPE "STM32G4"
#elif defined(STM32WB)
#warning STM32WB board selected
#define BOARD_TYPE "STM32WB"
#elif defined(STM32MP1)
#warning STM32MP1 board selected
#define BOARD_TYPE "STM32MP1"
#else
#warning STM32 unknown board selected
#define BOARD_TYPE "STM32 Unknown"
#endif
#ifndef BOARD_NAME
#define BOARD_NAME BOARD_TYPE
#endif
#include <LwIP.h>
#include <STM32Ethernet.h>
//#include <AsyncUDP_STM32.h>
// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20
byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
};
// Select the static IP address according to your local network
IPAddress ip(192, 168, 2, 232);
#endif //defines_h

View File

@ -1,19 +1,19 @@
{
"name":"AsyncHTTPRequest_Generic",
"version": "1.0.0",
"description":"Simple Async HTTP Request library, supporting GET and POST, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.",
"keywords":"async,tcp,http,ESP8266,ESP32,ESPAsyncTCP,AsyncTCP_STM32,stm32,ethernet,wifi,lan8742a",
"description":"Simple Async HTTP Request library, supporting GET and POST, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, etc... for ESP32, ESP8266.",
"keywords":"async,tcp,http,ESP8266,ESP32,ESPAsyncTCP,AsyncTCP,ethernet,wifi,lan8742a",
"authors": [
{
"name": "Bob Lemaire",
"url": "https://github.com/boblemaire",
}
"url": "https://github.com/boblemaire"
},
{
"name": "Khoi Hoang",
"url": "https://github.com/khoih-prog",
"email": "khoih.prog@gmail.com",
"maintainer": true,
}
"maintainer": true
}
],
"repository":
{
@ -37,16 +37,8 @@
"platforms": ["espressif8266", "espressif32"]
},
{
"name": "STM32duino LwIP",
"platforms": "ststm32"
},
{
"name": "STM32duino STM32Ethernet",
"platforms": "ststm32"
}
{
"name": "STM32 AsyncTCP",
"platforms": "ststm32"
"name": "https://github.com/0xFEEDC0DE64/optional.git",
"platforms": ["espressif8266", "espressif32"]
}
]
}

View File

@ -3,10 +3,10 @@ version=1.0.0
author=Bob Lemaire,Khoi Hoang
maintainer=Khoi Hoang <khoih.prog@gmail.com>
license=MIT
sentence=Simple Async HTTP Request library, supporting GET and POST, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.
paragraph=This AsyncHTTPRequest_Generic Library, supporting GET and POST, for ESP32, ESP8266 and STM32 with built-in LAN8742A Ethernet, such as Nucleo-144 F767ZI, etc.
sentence=Simple Async HTTP Request library, supporting GET and POST, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, etc.. for ESP32, ESP8266
paragraph=This AsyncHTTPRequest_Generic Library, supporting GET and POST, for ESP32, ESP8266.
category=Communication,AsyncTCP,AsyncHTTP
url=https://github.com/khoih-prog/AsyncHTTPRequest_Generic
architectures=*
depends=AsyncTCP,ESP AsyncTCP,ESPAsync_WiFiManager,STM32duino LwIP,STM32duino STM32Ethernet,STM32 AsyncTCP
depends=AsyncTCP,ESP AsyncTCP,ESPAsync_WiFiManager
includes=AsyncHTTPRequest_Generic.h

View File

@ -15,13 +15,11 @@
; ESP32
; SAMD
; NRF52
; STM32
; ============================================================
;default_envs = ESP8266
default_envs = ESP32
;default_envs = SAMD
;default_envs = NRF52
;default_envs = STM32
[env]
; ============================================================
@ -33,13 +31,15 @@ upload_speed = 921600
;monitor_speed = 9600
;monitor_port = COM11
lib_deps =
lib_deps =
; PlatformIO 4.x
AsyncTCP@~1.1.1
ESP AsyncTCP@~1.2.2
STM32 AsyncTCP@~1.0.0
STM32duino LwIP@~2.1.2
STM32duino STM32Ethernet@~1.2.0
ESPAsync_WiFiManager@~1.1.1
ESPAsyncTCP@~1.2.2
ESPAsync_WiFiManager@~1.1.2
; PlatformIO 5.x
; me-no-dev/AsyncTCP@~1.1.1
; me-no-dev/ESPAsyncTCP@~1.2.2
; khoih-prog/ESPAsync_WiFiManager@~1.1.2
build_flags =
; set your debug output (default=Serial)
@ -226,115 +226,3 @@ board = feather52840
;board = mdbt50qrx
;board = ninab302
;board = ninab112
[env:STM32]
platform = ststm32
framework = arduino
; ============================================================
; Choose your board by uncommenting one of the following lines
; ============================================================
; ============================================================
; Board configuration Nucleo-144
; ============================================================
;board = nucleo_f207zg
;board = nucleo_f429zi
;board = nucleo_f746zg
;board = nucleo_f756zg
;board = nucleo_f767zi
;board = nucleo_h743zi
;board = nucleo_l496zg
;board = nucleo_l496zg-p
;board = nucleo_l4r5zi
;board = nucleo_l4r5zi-p
; ============================================================
; Board configuration Nucleo-64
; ============================================================
;board = nucleo_f030r8
;board = nucleo_f072rb
;board = nucleo_f091rc
;board = nucleo_f103rb
;board = nucleo_f302r8
;board = nucleo_f303re
;board = nucleo_f401re
;board = nucleo_f411re
;board = nucleo_f446re
;board = nucleo_g071rb
;board = nucleo_g431rb
;board = nucleo_g474re
;board = nucleo_l053r8
;board = nucleo_l073rz
;board = nucleo_l152re
;board = nucleo_l433rc_p
;board = nucleo_l452re
;board = nucleo_l452re-p
;board = nucleo_l476rg
;board = pnucleo_wb55rg
; ============================================================
; Board configuration Nucleo-32
; ============================================================
;board = nucleo_f031k6
;board = nucleo_l031k6
;board = nucleo_l412kb
;board = nucleo_l432lc
;board = nucleo_f303k8
;board = nucleo_g431kb
; ============================================================
; Board configuration Discovery Boards
; ============================================================
;board = disco_f030r8
;board = disco_f072rb
;board = disco_f030r8
;board = disco_f100rb
;board = disco_f407vg
;board = disco_f413zh
;board = disco_f746ng
;board = disco_g0316
;board = disco_l475vg_iot
;board = disco_f072cz-lrwan1
; ============================================================
; Board configuration STM32MP1 Boards
; ============================================================
;board = stm32mp157a-dk1
;board = stm32mp157c-dk2
; ============================================================
; Board configuration Generic Boards
; ============================================================
;board = bluepill_f103c6
;board = bluepill_f103c8
;board = blackpill_f103c8
;board = stm32f103cx
;board = stm32f103rx
;board = stm32f103tx
;board = stm32f103vx
;board = stm32f103zx
;board = stm32f103zet6
;board = maplemini_f103cb
;board = blackpill_f303cc
;board = black_f407ve
;board = black_f407vg
;board = black_f407ze
;board = black_f407zg
;board = blue_f407ve_mini
;board = blackpill_f401cc
;board = blackpill_f411ce
;board = coreboard_f401rc
;board = feather_f405
; ============================================================
; Board configuration Many more Boards to be filled
; ============================================================

View File

@ -1,5 +1,5 @@
/****************************************************************************************************************************
AsyncHTTPRequest_Impl_Generic.h - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
AsyncHTTPRequest.cpp - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
@ -23,37 +23,97 @@
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
#pragma once
#ifndef AsyncHTTPRequest_Impl_Generic_h
#define AsyncHTTPRequest_Impl_Generic_h
#include "AsyncHTTPRequest.h"
//**************************************************************************************************************
AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(readyStateUnsent), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET)
, _timeout(DEFAULT_RX_TIMEOUT), _lastActivity(0), _requestStartTime(0), _requestEndTime(0), _URL(nullptr)
, _connectedHost(nullptr), _connectedPort(-1), _client(nullptr), _contentLength(0), _contentRead(0)
, _readyStateChangeCB(nullptr), _readyStateChangeCBarg(nullptr), _onDataCB(nullptr), _onDataCBarg(nullptr)
, _request(nullptr), _response(nullptr), _chunks(nullptr), _headers(nullptr)
namespace {
#if ESP32
class LockHelper
{
#ifdef ESP32
threadLock = xSemaphoreCreateRecursiveMutex();
public:
LockHelper(QueueHandle_t _xMutex) :
xMutex{_xMutex}
{
xSemaphoreTakeRecursive(xMutex, portMAX_DELAY);
}
~LockHelper()
{
xSemaphoreGiveRecursive(xMutex);
}
private:
const QueueHandle_t xMutex;
};
#define _lock LockHelper lock{this->threadLock}
#define _unlock
#elif ESP8266
#define _lock
#define _unlock
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#define _lock
#define _unlock
#endif
}
std::optional<URL> parseURL(const String &url)
{
int hostBeg = 0;
URL _URL;
_URL.scheme = "HTTP://";
if (url.substring(0, 7).equalsIgnoreCase("HTTP://"))
{
hostBeg += 7;
}
else if (url.substring(0, 8).equalsIgnoreCase("HTTPS://"))
return {};
int pathBeg = url.indexOf('/', hostBeg);
if (pathBeg < 0)
return {};
int hostEnd = pathBeg;
int portBeg = url.indexOf(':', hostBeg);
if (portBeg > 0 && portBeg < pathBeg)
{
_URL.port = url.substring(portBeg + 1, pathBeg).toInt();
hostEnd = portBeg;
}
else
_URL.port = 80;
_URL.host = url.substring(hostBeg, hostEnd);
int queryBeg = url.indexOf('?');
if (queryBeg < 0)
queryBeg = url.length();
_URL.path = url.substring(pathBeg, queryBeg);
_URL.query = url.substring(queryBeg);
AHTTP_LOGDEBUG2("_parseURL(): scheme+host", _URL.scheme, _URL.host);
AHTTP_LOGDEBUG3("_parseURL(): port+path+query", _URL.port, _URL.path, _URL.query);
return _URL;
}
//**************************************************************************************************************
AsyncHTTPRequest::~AsyncHTTPRequest()
{
if (_client)
_client->close(true);
delete _URL;
delete _headers;
delete _request;
delete _response;
delete _chunks;
delete[] _connectedHost;
#ifdef ESP32
vSemaphoreDelete(threadLock);
@ -73,73 +133,67 @@ void AsyncHTTPRequest::setDebug(bool debug)
}
//**************************************************************************************************************
bool AsyncHTTPRequest::debug()
bool AsyncHTTPRequest::debug() const
{
return (_debug);
return _debug;
}
//**************************************************************************************************************
bool AsyncHTTPRequest::open(const char* method, const char* URL)
bool AsyncHTTPRequest::open(const URL &url, HTTPmethod method)
{
AHTTP_LOGDEBUG3("open(", method, ", url =", URL);
AHTTP_LOGDEBUG3("open(url =", url.toString(), ", method =", toString<String>(method));
if (_readyState != readyStateUnsent && _readyState != readyStateDone)
switch (_readyState)
{
case ReadyState::Idle:
case ReadyState::Unsent:
case ReadyState::Done:
break;
default:
return false;
}
_requestStartTime = millis();
delete _URL;
delete _headers;
delete _request;
delete _response;
delete _chunks;
_URL = nullptr;
_headers = nullptr;
_response = nullptr;
_request = nullptr;
_chunks = nullptr;
_chunked = false;
_contentRead = 0;
_readyState = readyStateUnsent;
_readyState = ReadyState::Unsent;
_HTTPmethod = method;
if (strcmp(method, "GET") == 0)
{
_HTTPmethod = HTTPmethodGET;
}
else if (strcmp(method, "POST") == 0)
{
_HTTPmethod = HTTPmethodPOST;
}
else
return false;
_URL = url;
if (!_parseURL(URL))
{
return false;
}
if ( _client && _client->connected() && (strcmp(_URL->host, _connectedHost) != 0 || _URL->port != _connectedPort))
if ( _client && _client->connected() && (_URL.host != _connectedHost || _URL.port != _connectedPort))
{
return false;
}
char* hostName = new char[strlen(_URL->host) + 10];
sprintf(hostName, "%s:%d", _URL->host, _URL->port);
_addHeader("host", hostName);
delete[] hostName;
_addHeader("host", _URL.host + ':' + _URL.port);
_lastActivity = millis();
return _connect();
}
//**************************************************************************************************************
void AsyncHTTPRequest::onReadyStateChange(readyStateChangeCB cb, void* arg)
void AsyncHTTPRequest::onReadyStateChange(readyStateChangeCB cb, callback_arg_t arg)
{
_readyStateChangeCB = cb;
_readyStateChangeCBarg = arg;
}
//**************************************************************************************************************
void AsyncHTTPRequest::onReadyStateChangeArg(callback_arg_t arg)
{
_readyStateChangeCBarg = arg;
}
//**************************************************************************************************************
void AsyncHTTPRequest::setTimeout(int seconds)
{
@ -155,7 +209,7 @@ bool AsyncHTTPRequest::send()
_lock;
if ( ! _buildRequest())
if (!_buildRequest())
return false;
_send();
@ -265,13 +319,13 @@ void AsyncHTTPRequest::abort()
_unlock;
}
//**************************************************************************************************************
reqStates AsyncHTTPRequest::readyState()
ReadyState AsyncHTTPRequest::readyState() const
{
return _readyState;
}
//**************************************************************************************************************
int AsyncHTTPRequest::responseHTTPcode()
int AsyncHTTPRequest::responseHTTPcode() const
{
return _HTTPcode;
}
@ -283,7 +337,7 @@ String AsyncHTTPRequest::responseText()
_lock;
if ( ! _response || _readyState < readyStateLoading || ! available())
if ( ! _response || _readyState < ReadyState::Loading || ! available())
{
AHTTP_LOGDEBUG("responseText() no data");
@ -299,7 +353,7 @@ String AsyncHTTPRequest::responseText()
{
AHTTP_LOGDEBUG("responseText() no buffer");
_HTTPcode = HTTPCODE_TOO_LESS_RAM;
_HTTPcode = HttpCode::TOO_LESS_RAM;
_client->abort();
_unlock;
@ -319,7 +373,7 @@ String AsyncHTTPRequest::responseText()
//**************************************************************************************************************
size_t AsyncHTTPRequest::responseRead(uint8_t* buf, size_t len)
{
if ( ! _response || _readyState < readyStateLoading || ! available())
if ( ! _response || _readyState < ReadyState::Loading || ! available())
{
//DEBUG_HTTP("responseRead() no data\r\n");
AHTTP_LOGDEBUG("responseRead() no data");
@ -340,9 +394,9 @@ size_t AsyncHTTPRequest::responseRead(uint8_t* buf, size_t len)
}
//**************************************************************************************************************
size_t AsyncHTTPRequest::available()
size_t AsyncHTTPRequest::available() const
{
if (_readyState < readyStateLoading)
if (_readyState < ReadyState::Loading)
return 0;
if (_chunked && (_contentLength - _contentRead) < _response->available())
@ -354,9 +408,9 @@ size_t AsyncHTTPRequest::available()
}
//**************************************************************************************************************
size_t AsyncHTTPRequest::responseLength()
size_t AsyncHTTPRequest::responseLength() const
{
if (_readyState < readyStateLoading)
if (_readyState < ReadyState::Loading)
return 0;
return _contentLength;
@ -372,12 +426,12 @@ void AsyncHTTPRequest::onData(onDataCB cb, void* arg)
}
//**************************************************************************************************************
uint32_t AsyncHTTPRequest::elapsedTime()
uint32_t AsyncHTTPRequest::elapsedTime() const
{
if (_readyState <= readyStateOpened)
if (_readyState <= ReadyState::Opened)
return 0;
if (_readyState != readyStateDone)
if (_readyState != ReadyState::Done)
{
return millis() - _requestStartTime;
}
@ -386,7 +440,7 @@ uint32_t AsyncHTTPRequest::elapsedTime()
}
//**************************************************************************************************************
String AsyncHTTPRequest::version()
String AsyncHTTPRequest::version() const
{
return String(AsyncHTTPRequest_Generic_version);
}
@ -400,64 +454,6 @@ String AsyncHTTPRequest::version()
P R R OOO T EEEEE CCC T EEEEE DDDD
_______________________________________________________________________________________________________________*/
//**************************************************************************************************************
bool AsyncHTTPRequest::_parseURL(const char* url)
{
return _parseURL(String(url));
}
//**************************************************************************************************************
bool AsyncHTTPRequest::_parseURL(String url)
{
delete _URL;
int hostBeg = 0;
_URL = new URL;
_URL->scheme = new char[8];
strcpy(_URL->scheme, "HTTP://");
if (url.substring(0, 7).equalsIgnoreCase("HTTP://"))
{
hostBeg += 7;
}
else if (url.substring(0, 8).equalsIgnoreCase("HTTPS://"))
{
return false;
}
int pathBeg = url.indexOf('/', hostBeg);
if (pathBeg < 0)
return false;
int hostEnd = pathBeg;
int portBeg = url.indexOf(':', hostBeg);
if (portBeg > 0 && portBeg < pathBeg)
{
_URL->port = url.substring(portBeg + 1, pathBeg).toInt();
hostEnd = portBeg;
}
_URL->host = new char[hostEnd - hostBeg + 1];
strcpy(_URL->host, url.substring(hostBeg, hostEnd).c_str());
int queryBeg = url.indexOf('?');
if (queryBeg < 0)
queryBeg = url.length();
_URL->path = new char[queryBeg - pathBeg + 1];
strcpy(_URL->path, url.substring(pathBeg, queryBeg).c_str());
_URL->query = new char[url.length() - queryBeg + 1];
strcpy(_URL->query, url.substring(queryBeg).c_str());
AHTTP_LOGDEBUG2("_parseURL(): scheme+host", _URL->scheme, _URL->host);
AHTTP_LOGDEBUG3("_parseURL(): port+path+query", _URL->port, _URL->path, _URL->query);
return true;
}
//**************************************************************************************************************
bool AsyncHTTPRequest::_connect()
{
@ -468,11 +464,8 @@ bool AsyncHTTPRequest::_connect()
_client = new AsyncClient();
}
delete[] _connectedHost;
_connectedHost = new char[strlen(_URL->host) + 1];
strcpy(_connectedHost, _URL->host);
_connectedPort = _URL->port;
_connectedHost = _URL.host;
_connectedPort = _URL.port;
_client->onConnect([](void *obj, AsyncClient * client)
{
@ -496,12 +489,12 @@ bool AsyncHTTPRequest::_connect()
if ( ! _client->connected())
{
if ( ! _client->connect(_URL->host, _URL->port))
if ( ! _client->connect(_URL.host.c_str(), _URL.port))
{
AHTTP_LOGDEBUG3("client.connect failed:", _URL->host, ",", _URL->port);
AHTTP_LOGDEBUG3("client.connect failed:", _URL.host, ",", _URL.port);
_HTTPcode = HTTPCODE_NOT_CONNECTED;
_setReadyState(readyStateDone);
_HTTPcode = HttpCode::NOT_CONNECTED;
_setReadyState(ReadyState::Done);
return false;
}
@ -525,14 +518,12 @@ bool AsyncHTTPRequest::_buildRequest()
if ( ! _request)
_request = new xbuf;
_request->write(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ");
_request->write(_URL->path);
_request->write(_URL->query);
_request->write(toString<String>(_HTTPmethod));
_request->write(' ');
_request->write(_URL.path);
_request->write(_URL.query);
_request->write(" HTTP/1.1\r\n");
delete _URL;
_URL = nullptr;
header* hdr = _headers;
while (hdr)
@ -546,6 +537,7 @@ bool AsyncHTTPRequest::_buildRequest()
delete _headers;
_headers = nullptr;
_request->write("\r\n");
return true;
@ -600,13 +592,13 @@ size_t AsyncHTTPRequest::_send()
}
//**************************************************************************************************************
void AsyncHTTPRequest::_setReadyState(reqStates newState)
void AsyncHTTPRequest::_setReadyState(ReadyState readyState)
{
if (_readyState != newState)
if (_readyState != readyState)
{
_readyState = newState;
_readyState = readyState;
AHTTP_LOGDEBUG1("_setReadyState :", _readyState);
AHTTP_LOGDEBUG1("_setReadyState :", int(_readyState));
if (_readyStateChangeCB)
{
@ -639,9 +631,9 @@ void AsyncHTTPRequest::_processChunks()
if (chunkLength == 0)
{
char* connectionHdr = respHeaderValue("connection");
const auto connectionHdr = respHeaderValue("connection");
if (connectionHdr && (strcasecmp_P(connectionHdr, PSTR("disconnect")) == 0))
if (connectionHdr && connectionHdr == "disconnect")
{
AHTTP_LOGDEBUG("*all chunks received - closing TCP");
@ -655,7 +647,7 @@ void AsyncHTTPRequest::_processChunks()
_requestEndTime = millis();
_lastActivity = 0;
_timeout = 0;
_setReadyState(readyStateDone);
_setReadyState(ReadyState::Done);
return;
}
@ -678,7 +670,7 @@ void AsyncHTTPRequest::_onConnect(AsyncClient* client)
_lock;
_client = client;
_setReadyState(readyStateOpened);
_setReadyState(ReadyState::Opened);
_response = new xbuf;
_contentLength = 0;
_contentRead = 0;
@ -711,7 +703,7 @@ void AsyncHTTPRequest::_onPoll(AsyncClient* client)
if (_timeout && (millis() - _lastActivity) > (_timeout * 1000))
{
_client->close();
_HTTPcode = HTTPCODE_TIMEOUT;
_HTTPcode = HttpCode::TIMEOUT;
AHTTP_LOGDEBUG("_onPoll timeout");
}
@ -739,26 +731,25 @@ void AsyncHTTPRequest::_onDisconnect(AsyncClient* client)
_lock;
if (_readyState < readyStateOpened)
if (_readyState < ReadyState::Opened)
{
_HTTPcode = HTTPCODE_NOT_CONNECTED;
_HTTPcode = HttpCode::NOT_CONNECTED;
}
else if (_HTTPcode > 0 &&
(_readyState < readyStateHdrsRecvd || (_contentRead + _response->available()) < _contentLength))
(_readyState < ReadyState::HdrsRecvd || (_contentRead + _response->available()) < _contentLength))
{
_HTTPcode = HTTPCODE_CONNECTION_LOST;
_HTTPcode = HttpCode::CONNECTION_LOST;
}
delete _client;
_client = nullptr;
delete[] _connectedHost;
_connectedHost = nullptr;
_connectedHost = String{};
_connectedPort = -1;
_requestEndTime = millis();
_lastActivity = 0;
_setReadyState(readyStateDone);
_setReadyState(ReadyState::Done);
_unlock;
}
@ -781,24 +772,24 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
}
// if headers not complete, collect them. If still not complete, just return.
if (_readyState == readyStateOpened)
if (_readyState == ReadyState::Opened)
{
if ( ! _collectHeaders())
return;
}
// If there's data in the buffer and not Done, advance readyState to Loading.
if (_response->available() && _readyState != readyStateDone)
if (_response->available() && _readyState != ReadyState::Done)
{
_setReadyState(readyStateLoading);
_setReadyState(ReadyState::Loading);
}
// If not chunked and all data read, close it up.
if ( ! _chunked && (_response->available() + _contentRead) >= _contentLength)
{
char* connectionHdr = respHeaderValue("connection");
const auto connectionHdr = respHeaderValue("connection");
if (connectionHdr && (strcasecmp_P(connectionHdr, PSTR("disconnect")) == 0))
if (connectionHdr && connectionHdr == "disconnect")
{
AHTTP_LOGDEBUG("*all data received - closing TCP");
@ -812,7 +803,7 @@ void AsyncHTTPRequest::_onData(void* Vbuf, size_t len)
_requestEndTime = millis();
_lastActivity = 0;
_timeout = 0;
_setReadyState(readyStateDone);
_setReadyState(ReadyState::Done);
}
// If onData callback requested, do so.
@ -844,7 +835,7 @@ bool AsyncHTTPRequest::_collectHeaders()
// If empty line, all headers are in, advance readyState.
if (headerLine.length() == 2)
{
_setReadyState(readyStateHdrsRecvd);
_setReadyState(ReadyState::HdrsRecvd);
}
// If line is HTTP header, capture HTTPcode.
else if (headerLine.substring(0, 7) == "HTTP/1.")
@ -865,20 +856,20 @@ bool AsyncHTTPRequest::_collectHeaders()
_addHeader(name.c_str(), value.c_str());
}
}
} while (_readyState == readyStateOpened);
} while (_readyState == ReadyState::Opened);
// If content-Length header, set _contentLength
header *hdr = _getHeader("Content-Length");
if (hdr)
{
_contentLength = strtol(hdr->value, nullptr, 10);
_contentLength = hdr->value.toInt();
}
// If chunked specified, try to set _contentLength to size of first chunk
hdr = _getHeader("Transfer-Encoding");
if (hdr && strcasecmp_P(hdr->value, PSTR("chunked")) == 0)
if (hdr && hdr->value == "chunked")
{
AHTTP_LOGDEBUG("*transfer-encoding: chunked");
@ -905,7 +896,7 @@ bool AsyncHTTPRequest::_collectHeaders()
//**************************************************************************************************************
void AsyncHTTPRequest::setReqHeader(const char* name, const char* value)
{
if (_readyState <= readyStateOpened && _headers)
if (_readyState <= ReadyState::Opened && _headers)
{
_addHeader(name, value);
}
@ -914,7 +905,7 @@ void AsyncHTTPRequest::setReqHeader(const char* name, const char* value)
//**************************************************************************************************************
void AsyncHTTPRequest::setReqHeader(const char* name, int32_t value)
{
if (_readyState <= readyStateOpened && _headers)
if (_readyState <= ReadyState::Opened && _headers)
{
setReqHeader(name, String(value).c_str());
}
@ -925,7 +916,7 @@ void AsyncHTTPRequest::setReqHeader(const char* name, int32_t value)
//**************************************************************************************************************
void AsyncHTTPRequest::setReqHeader(const char* name, const __FlashStringHelper* value)
{
if (_readyState <= readyStateOpened && _headers)
if (_readyState <= ReadyState::Opened && _headers)
{
char* _value = _charstar(value);
_addHeader(name, _value);
@ -936,7 +927,7 @@ void AsyncHTTPRequest::setReqHeader(const char* name, const __FlashStringHelper*
//**************************************************************************************************************
void AsyncHTTPRequest::setReqHeader(const __FlashStringHelper *name, const char* value)
{
if (_readyState <= readyStateOpened && _headers)
if (_readyState <= ReadyState::Opened && _headers)
{
char* _name = _charstar(name);
_addHeader(_name, value);
@ -947,7 +938,7 @@ void AsyncHTTPRequest::setReqHeader(const __FlashStringHelper *name, const char*
//**************************************************************************************************************
void AsyncHTTPRequest::setReqHeader(const __FlashStringHelper *name, const __FlashStringHelper* value)
{
if (_readyState <= readyStateOpened && _headers)
if (_readyState <= ReadyState::Opened && _headers)
{
char* _name = _charstar(name);
char* _value = _charstar(value);
@ -960,7 +951,7 @@ void AsyncHTTPRequest::setReqHeader(const __FlashStringHelper *name, const __Fla
//**************************************************************************************************************
void AsyncHTTPRequest::setReqHeader(const __FlashStringHelper *name, int32_t value)
{
if (_readyState <= readyStateOpened && _headers)
if (_readyState <= ReadyState::Opened && _headers)
{
char* _name = _charstar(name);
setReqHeader(_name, String(value).c_str());
@ -973,7 +964,7 @@ void AsyncHTTPRequest::setReqHeader(const __FlashStringHelper *name, int32_t val
//**************************************************************************************************************
int AsyncHTTPRequest::respHeaderCount()
{
if (_readyState < readyStateHdrsRecvd)
if (_readyState < ReadyState::HdrsRecvd)
return 0;
int count = 0;
@ -989,76 +980,69 @@ int AsyncHTTPRequest::respHeaderCount()
}
//**************************************************************************************************************
char* AsyncHTTPRequest::respHeaderName(int ndx)
String AsyncHTTPRequest::respHeaderName(int ndx)
{
if (_readyState < readyStateHdrsRecvd)
return nullptr;
if (_readyState < ReadyState::HdrsRecvd)
return {};
header* hdr = _getHeader(ndx);
if ( ! hdr)
return nullptr;
return {};
return hdr->name;
}
//**************************************************************************************************************
char* AsyncHTTPRequest::respHeaderValue(const char* name)
String AsyncHTTPRequest::respHeaderValue(const String &name)
{
if (_readyState < readyStateHdrsRecvd)
return nullptr;
if (_readyState < ReadyState::HdrsRecvd)
return {};
header* hdr = _getHeader(name);
if ( ! hdr)
return nullptr;
return {};
return hdr->value;
}
//**************************************************************************************************************
char* AsyncHTTPRequest::respHeaderValue(int ndx)
String AsyncHTTPRequest::respHeaderValue(int ndx)
{
if (_readyState < readyStateHdrsRecvd)
return nullptr;
if (_readyState < ReadyState::HdrsRecvd)
return {};
header* hdr = _getHeader(ndx);
if ( ! hdr)
return nullptr;
return {};
return hdr->value;
}
//**************************************************************************************************************
bool AsyncHTTPRequest::respHeaderExists(const char* name)
bool AsyncHTTPRequest::respHeaderExists(const String &name)
{
if (_readyState < readyStateHdrsRecvd)
if (_readyState < ReadyState::HdrsRecvd)
return false;
header* hdr = _getHeader(name);
if ( ! hdr)
return false;
return true;
return _getHeader(name);
}
#if (ESP32 || ESP8266)
//**************************************************************************************************************
char* AsyncHTTPRequest::respHeaderValue(const __FlashStringHelper *name)
String AsyncHTTPRequest::respHeaderValue(const __FlashStringHelper *name)
{
if (_readyState < readyStateHdrsRecvd)
return nullptr;
if (_readyState < ReadyState::HdrsRecvd)
return {};
char* _name = _charstar(name);
header* hdr = _getHeader(_name);
delete[] _name;
header* hdr = _getHeader(name);
if ( ! hdr)
return nullptr;
return {};
return hdr->value;
}
@ -1066,17 +1050,10 @@ char* AsyncHTTPRequest::respHeaderValue(const __FlashStringHelper *name)
//**************************************************************************************************************
bool AsyncHTTPRequest::respHeaderExists(const __FlashStringHelper *name)
{
if (_readyState < readyStateHdrsRecvd)
if (_readyState < ReadyState::HdrsRecvd)
return false;
char* _name = _charstar(name);
header* hdr = _getHeader(_name);
delete[] _name;
if ( ! hdr)
return false;
return true;
return _getHeader(name);
}
#endif
@ -1104,14 +1081,14 @@ String AsyncHTTPRequest::headers()
}
//**************************************************************************************************************
AsyncHTTPRequest::header* AsyncHTTPRequest::_addHeader(const char* name, const char* value)
AsyncHTTPRequest::header* AsyncHTTPRequest::_addHeader(const String &name, const String &value)
{
_lock;
header* hdr = (header*) &_headers;
while (hdr->next)
{
if (strcasecmp(name, hdr->next->name) == 0)
if (name.equalsIgnoreCase(hdr->next->name))
{
header* oldHdr = hdr->next;
hdr->next = hdr->next->next;
@ -1125,24 +1102,22 @@ AsyncHTTPRequest::header* AsyncHTTPRequest::_addHeader(const char* name, const
}
hdr->next = new header;
hdr->next->name = new char[strlen(name) + 1];
strcpy(hdr->next->name, name);
hdr->next->value = new char[strlen(value) + 1];
strcpy(hdr->next->value, value);
hdr->next->name = name;
hdr->next->value = value;
_unlock;
return hdr->next;
}
//**************************************************************************************************************
AsyncHTTPRequest::header* AsyncHTTPRequest::_getHeader(const char* name)
AsyncHTTPRequest::header* AsyncHTTPRequest::_getHeader(const String &name)
{
_lock;
header* hdr = _headers;
while (hdr)
{
if (strcasecmp(name, hdr->name) == 0)
if (name.equalsIgnoreCase(hdr->name))
break;
hdr = hdr->next;
@ -1187,5 +1162,3 @@ char* AsyncHTTPRequest::_charstar(const __FlashStringHelper * str)
}
#endif
#endif // AsyncHTTPRequest_Impl_Generic_h

318
src/AsyncHTTPRequest.h Normal file
View File

@ -0,0 +1,318 @@
/****************************************************************************************************************************
AsyncHTTPRequest_Generic.h - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_STM32 is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
#pragma once
#define AsyncHTTPRequest_Generic_version "1.0.0"
#include <Arduino.h>
#include <WString.h>
#include <optional>
#include "AsyncHTTPRequest_Debug.h"
#ifndef DEBUG_IOTA_PORT
#define DEBUG_IOTA_PORT Serial
#endif
#ifdef DEBUG_IOTA_HTTP
#define DEBUG_IOTA_HTTP_SET true
#else
#define DEBUG_IOTA_HTTP_SET false
#endif
#if ESP32
#include <AsyncTCP.h>
#elif ESP8266
#include <ESPAsyncTCP.h>
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#include "STM32AsyncTCP.h"
#endif
#include <pgmspace.h>
#include <utility/xbuf.h>
#define DEBUG_HTTP(format,...) if(_debug){\
DEBUG_IOTA_PORT.printf("Debug(%3ld): ", millis()-_requestStartTime);\
DEBUG_IOTA_PORT.printf_P(PSTR(format),##__VA_ARGS__);}
#define DEFAULT_RX_TIMEOUT 3 // Seconds for timeout
namespace HttpCode
{
enum
{
CONNECTION_REFUSED = -1,
SEND_HEADER_FAILED = -2,
SEND_PAYLOAD_FAILED = -3,
NOT_CONNECTED = -4,
CONNECTION_LOST = -5,
NO_STREAM = -6,
NO_HTTP_SERVER = -7,
TOO_LESS_RAM = -8,
ENCODING = -9,
STREAM_WRITE = -10,
TIMEOUT = -11,
};
inline String toString(int code)
{
switch (code)
{
case CONNECTION_REFUSED: return "CONNECTION_REFUSED";
case SEND_HEADER_FAILED: return "SEND_HEADER_FAILED";
case SEND_PAYLOAD_FAILED: return "SEND_PAYLOAD_FAILED";
case NOT_CONNECTED: return "NOT_CONNECTED";
case CONNECTION_LOST: return "CONNECTION_LOST";
case NO_STREAM: return "NO_STREAM";
case NO_HTTP_SERVER: return "NO_HTTP_SERVER";
case TOO_LESS_RAM: return "TOO_LESS_RAM";
case ENCODING: return "ENCODING";
case STREAM_WRITE: return "STREAM_WRITE";
case TIMEOUT: return "TIMEOUT";
}
return String{code};
}
}
enum class ReadyState
{
Idle, // Client created, open not yet called
Unsent, // open() has been called, not connected
Opened, // open() has been called, connected
HdrsRecvd, // send() called, response headers available
Loading, // receiving, partial data available
Done // Request complete, all data available.
};
namespace {
//! Helper utility to convert a ReadyState into a string
//! String library agnostic, can be used with std::string or Arduino's WString
template<typename T>
T toString(ReadyState state)
{
switch (state)
{
case ReadyState::Idle: return "Idle";
case ReadyState::Unsent: return "Unsent";
case ReadyState::Opened: return "Opened";
case ReadyState::HdrsRecvd: return "HdrsRecvd";
case ReadyState::Loading: return "Loading";
case ReadyState::Done: return "Done";
}
return T{"Unknown ReadyState("} + int(state) + ')';
}
}
enum class HTTPmethod
{
GET,
POST
};
namespace {
//! Helper utility to convert a HTTPmethod into a string
//! String library agnostic, can be used with std::string or Arduino's WString
template<typename T>
T toString(HTTPmethod method)
{
switch (method)
{
case HTTPmethod::GET: return "GET";
case HTTPmethod::POST: return "POST";
}
return T{"Unknown HTTPmethod("} + int(method) + ')';
}
}
struct URL
{
String scheme;
String user;
String pwd;
String host;
int port;
String path;
String query;
String fragment;
String toString() const
{
return scheme + user + pwd + host + ':' + port + path + query + fragment;
}
};
std::optional<URL> parseURL(const String &url);
class AsyncHTTPRequest
{
using callback_arg_t = void*;
struct header
{
header* next{};
String name;
String value;
~header()
{
delete next;
}
};
using readyStateChangeCB = std::function<void(callback_arg_t, AsyncHTTPRequest*, ReadyState readyState)>;
using onDataCB = std::function<void(void*, AsyncHTTPRequest*, size_t available)>;
public:
~AsyncHTTPRequest();
//External functions in typical order of use:
//__________________________________________________________________________________________________________*/
void setDebug(bool); // Turn debug message on/off
bool debug() const; // is debug on or off?
bool open(const URL &url, HTTPmethod method = HTTPmethod::GET); // Initiate a request
void onReadyStateChange(readyStateChangeCB, callback_arg_t arg = 0); // Optional event handler for ready state change
void onReadyStateChangeArg(callback_arg_t arg = 0); // set event handlers arg
// or you can simply poll readyState()
void setTimeout(int seconds); // overide default timeout (seconds)
void setReqHeader(const char* name, const char* value); // add a request header
void setReqHeader(const char* name, int32_t value); // overload to use integer value
#if (ESP32 || ESP8266)
void setReqHeader(const char* name, const __FlashStringHelper* value);
void setReqHeader(const __FlashStringHelper *name, const char* value);
void setReqHeader(const __FlashStringHelper *name, const __FlashStringHelper* value);
void setReqHeader(const __FlashStringHelper *name, int32_t value);
#endif
bool send(); // Send the request (GET)
bool send(String body); // Send the request (POST)
bool send(const char* body); // Send the request (POST)
bool send(const uint8_t* buffer, size_t len); // Send the request (POST) (binary data?)
bool send(xbuf* body, size_t len); // Send the request (POST) data in an xbuf
void abort(); // Abort the current operation
ReadyState readyState() const; // Return the ready state
int respHeaderCount(); // Retrieve count of response headers
String respHeaderName(int index); // Return header name by index
String respHeaderValue(int index); // Return header value by index
String respHeaderValue(const String &name); // Return header value by name
bool respHeaderExists(const String &name); // Does header exist by name?
#if (ESP32 || ESP8266)
String respHeaderValue(const __FlashStringHelper *name);
bool respHeaderExists(const __FlashStringHelper *name);
#endif
const URL &url() const { return _URL; }
String headers(); // Return all headers as String
void onData(onDataCB, void* arg = 0); // Notify when min data is available
size_t available() const; // response available
size_t responseLength() const; // indicated response length or sum of chunks to date
int responseHTTPcode() const; // HTTP response code or (negative) error code
String responseText(); // response (whole* or partial* as string)
size_t responseRead(uint8_t* buffer, size_t len); // Read response into buffer
uint32_t elapsedTime() const; // Elapsed time of in progress transaction or last completed (ms)
String version() const; // Version of AsyncHTTPRequest
//___________________________________________________________________________________________________________________________________
private:
HTTPmethod _HTTPmethod;
ReadyState _readyState{ReadyState::Idle};
int16_t _HTTPcode{0}; // HTTP response code or (negative) exception code
bool _chunked{false}; // Processing chunked response
bool _debug{DEBUG_IOTA_HTTP_SET}; // Debug state
uint32_t _timeout{DEFAULT_RX_TIMEOUT}; // Default or user overide RxTimeout in seconds
uint32_t _lastActivity{0}; // Time of last activity
uint32_t _requestStartTime{0}; // Time last open() issued
uint32_t _requestEndTime{0}; // Time of last disconnect
URL _URL{}; // -> URL data structure
String _connectedHost; // Host when connected
int _connectedPort{-1}; // Port when connected
AsyncClient* _client{nullptr}; // ESPAsyncTCP AsyncClient instance
size_t _contentLength{0}; // content-length header value or sum of chunk headers
size_t _contentRead{0}; // number of bytes retrieved by user since last open()
readyStateChangeCB _readyStateChangeCB{}; // optional callback for readyState change
callback_arg_t _readyStateChangeCBarg{}; // associated user argument
onDataCB _onDataCB{nullptr}; // optional callback when data received
void* _onDataCBarg{nullptr}; // associated user argument
#ifdef ESP32
SemaphoreHandle_t threadLock{xSemaphoreCreateRecursiveMutex()};
#endif
// request and response String buffers and header list (same queue for request and response).
xbuf* _request{nullptr}; // Tx data buffer
xbuf* _response{nullptr}; // Rx data buffer for headers
xbuf* _chunks{nullptr}; // First stage for chunked response
header* _headers{nullptr}; // request or (readyState > readyStateHdrsRcvd) response headers
// Protected functions
header* _addHeader(const String &name, const String &value);
header* _getHeader(const String &name);
header* _getHeader(int idx);
bool _buildRequest();
void _processChunks();
bool _connect();
size_t _send();
void _setReadyState(ReadyState readyState);
#if (ESP32 || ESP8266)
char* _charstar(const __FlashStringHelper *str);
#endif
// callbacks
void _onConnect(AsyncClient*);
void _onDisconnect(AsyncClient*);
void _onData(void*, size_t);
void _onError(AsyncClient*, int8_t);
void _onPoll(AsyncClient*);
bool _collectHeaders();
};

View File

@ -24,8 +24,7 @@
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
#ifndef AsyncHTTPRequest_Debug_STM32_H
#define AsyncHTTPRequest_Debug_STM32_H
#pragma once
#ifdef ASYNC_HTTP_DEBUG_PORT
#define A_DBG_PORT ASYNC_HTTP_DEBUG_PORT
@ -67,5 +66,3 @@
#define AHTTP_LOGDEBUG1(x,y) if(_ASYNC_HTTP_LOGLEVEL_>3) { A_DBG_PORT.print("[AHTTP] "); A_DBG_PORT.print(x); A_DBG_PORT.print(" "); A_DBG_PORT.println(y); }
#define AHTTP_LOGDEBUG2(x,y,z) if(_ASYNC_HTTP_LOGLEVEL_>3) { A_DBG_PORT.print("[AHTTP] "); A_DBG_PORT.print(x); A_DBG_PORT.print(" "); A_DBG_PORT.print(y); A_DBG_PORT.print(" "); A_DBG_PORT.println(z); }
#define AHTTP_LOGDEBUG3(x,y,z,w) if(_ASYNC_HTTP_LOGLEVEL_>3) { A_DBG_PORT.print("[AHTTP] "); A_DBG_PORT.print(x); A_DBG_PORT.print(" "); A_DBG_PORT.print(y); A_DBG_PORT.print(" "); A_DBG_PORT.print(z); A_DBG_PORT.print(" "); A_DBG_PORT.println(w); }
#endif // AsyncHTTPRequest_Debug_STM32_H

View File

@ -1,269 +0,0 @@
/****************************************************************************************************************************
AsyncHTTPRequest_Generic.h - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_STM32 is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
*****************************************************************************************************************************/
#ifndef AsyncHTTPRequest_Generic_h
#define AsyncHTTPRequest_Generic_h
#define AsyncHTTPRequest_Generic_version "1.0.0"
#include <Arduino.h>
#include "AsyncHTTPRequest_Debug_Generic.h"
#ifndef DEBUG_IOTA_PORT
#define DEBUG_IOTA_PORT Serial
#endif
#ifdef DEBUG_IOTA_HTTP
#define DEBUG_IOTA_HTTP_SET true
#else
#define DEBUG_IOTA_HTTP_SET false
#endif
#if ESP32
#include <AsyncTCP.h>
#define _lock xSemaphoreTakeRecursive(threadLock,portMAX_DELAY)
#define _unlock xSemaphoreGiveRecursive(threadLock)
#elif ESP8266
#include <ESPAsyncTCP.h>
#define _lock
#define _unlock
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#include "STM32AsyncTCP.h"
#define _lock
#define _unlock
#endif
#include <pgmspace.h>
#include <utility/xbuf.h>
#define DEBUG_HTTP(format,...) if(_debug){\
DEBUG_IOTA_PORT.printf("Debug(%3ld): ", millis()-_requestStartTime);\
DEBUG_IOTA_PORT.printf_P(PSTR(format),##__VA_ARGS__);}
#define DEFAULT_RX_TIMEOUT 3 // Seconds for timeout
#define HTTPCODE_CONNECTION_REFUSED (-1)
#define HTTPCODE_SEND_HEADER_FAILED (-2)
#define HTTPCODE_SEND_PAYLOAD_FAILED (-3)
#define HTTPCODE_NOT_CONNECTED (-4)
#define HTTPCODE_CONNECTION_LOST (-5)
#define HTTPCODE_NO_STREAM (-6)
#define HTTPCODE_NO_HTTP_SERVER (-7)
#define HTTPCODE_TOO_LESS_RAM (-8)
#define HTTPCODE_ENCODING (-9)
#define HTTPCODE_STREAM_WRITE (-10)
#define HTTPCODE_TIMEOUT (-11)
typedef enum
{
readyStateUnsent = 0, // Client created, open not yet called
readyStateOpened = 1, // open() has been called, connected
readyStateHdrsRecvd = 2, // send() called, response headers available
readyStateLoading = 3, // receiving, partial data available
readyStateDone = 4 // Request complete, all data available.
} reqStates;
class AsyncHTTPRequest
{
struct header
{
header* next;
char* name;
char* value;
header(): next(nullptr), name(nullptr), value(nullptr)
{};
~header()
{
delete[] name;
delete[] value;
delete next;
}
};
struct URL
{
char* scheme;
char* user;
char* pwd;
char* host;
int port;
char* path;
char* query;
char* fragment;
URL(): scheme(nullptr), user(nullptr), pwd(nullptr), host(nullptr),
port(80), path(nullptr), query(nullptr), fragment(nullptr)
{};
~URL()
{
delete[] scheme;
delete[] user;
delete[] pwd;
delete[] host;
delete[] path;
delete[] query;
delete[] fragment;
}
};
typedef std::function<void(void*, AsyncHTTPRequest*, int readyState)> readyStateChangeCB;
typedef std::function<void(void*, AsyncHTTPRequest*, size_t available)> onDataCB;
public:
AsyncHTTPRequest();
~AsyncHTTPRequest();
//External functions in typical order of use:
//__________________________________________________________________________________________________________*/
void setDebug(bool); // Turn debug message on/off
bool debug(); // is debug on or off?
bool open(const char* /*GET/POST*/, const char* URL); // Initiate a request
void onReadyStateChange(readyStateChangeCB, void* arg = 0); // Optional event handler for ready state change
// or you can simply poll readyState()
void setTimeout(int); // overide default timeout (seconds)
void setReqHeader(const char* name, const char* value); // add a request header
void setReqHeader(const char* name, int32_t value); // overload to use integer value
#if (ESP32 || ESP8266)
void setReqHeader(const char* name, const __FlashStringHelper* value);
void setReqHeader(const __FlashStringHelper *name, const char* value);
void setReqHeader(const __FlashStringHelper *name, const __FlashStringHelper* value);
void setReqHeader(const __FlashStringHelper *name, int32_t value);
#endif
bool send(); // Send the request (GET)
bool send(String body); // Send the request (POST)
bool send(const char* body); // Send the request (POST)
bool send(const uint8_t* buffer, size_t len); // Send the request (POST) (binary data?)
bool send(xbuf* body, size_t len); // Send the request (POST) data in an xbuf
void abort(); // Abort the current operation
reqStates readyState(); // Return the ready state
int respHeaderCount(); // Retrieve count of response headers
char* respHeaderName(int index); // Return header name by index
char* respHeaderValue(int index); // Return header value by index
char* respHeaderValue(const char* name); // Return header value by name
bool respHeaderExists(const char* name); // Does header exist by name?
#if (ESP32 || ESP8266)
char* respHeaderValue(const __FlashStringHelper *name);
bool respHeaderExists(const __FlashStringHelper *name);
#endif
String headers(); // Return all headers as String
void onData(onDataCB, void* arg = 0); // Notify when min data is available
size_t available(); // response available
size_t responseLength(); // indicated response length or sum of chunks to date
int responseHTTPcode(); // HTTP response code or (negative) error code
String responseText(); // response (whole* or partial* as string)
size_t responseRead(uint8_t* buffer, size_t len); // Read response into buffer
uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms)
String version(); // Version of AsyncHTTPRequest
//___________________________________________________________________________________________________________________________________
private:
enum {HTTPmethodGET, HTTPmethodPOST} _HTTPmethod;
reqStates _readyState;
int16_t _HTTPcode; // HTTP response code or (negative) exception code
bool _chunked; // Processing chunked response
bool _debug; // Debug state
uint32_t _timeout; // Default or user overide RxTimeout in seconds
uint32_t _lastActivity; // Time of last activity
uint32_t _requestStartTime; // Time last open() issued
uint32_t _requestEndTime; // Time of last disconnect
URL* _URL; // -> URL data structure
char* _connectedHost; // Host when connected
int _connectedPort; // Port when connected
AsyncClient* _client; // ESPAsyncTCP AsyncClient instance
size_t _contentLength; // content-length header value or sum of chunk headers
size_t _contentRead; // number of bytes retrieved by user since last open()
readyStateChangeCB _readyStateChangeCB; // optional callback for readyState change
void* _readyStateChangeCBarg; // associated user argument
onDataCB _onDataCB; // optional callback when data received
void* _onDataCBarg; // associated user argument
#ifdef ESP32
SemaphoreHandle_t threadLock;
#endif
// request and response String buffers and header list (same queue for request and response).
xbuf* _request; // Tx data buffer
xbuf* _response; // Rx data buffer for headers
xbuf* _chunks; // First stage for chunked response
header* _headers; // request or (readyState > readyStateHdrsRcvd) response headers
// Protected functions
header* _addHeader(const char*, const char*);
header* _getHeader(const char*);
header* _getHeader(int);
bool _buildRequest();
bool _parseURL(const char*);
bool _parseURL(String);
void _processChunks();
bool _connect();
size_t _send();
void _setReadyState(reqStates);
#if (ESP32 || ESP8266)
char* _charstar(const __FlashStringHelper *str);
#endif
// callbacks
void _onConnect(AsyncClient*);
void _onDisconnect(AsyncClient*);
void _onData(void*, size_t);
void _onError(AsyncClient*, int8_t);
void _onPoll(AsyncClient*);
bool _collectHeaders();
};
#include "AsyncHTTPRequest_Impl_Generic.h"
#endif // AsyncHTTPRequest_Generic_h

View File

@ -27,7 +27,7 @@
#ifndef xbuf_Impl_h
#define xbuf_Impl_h
//#include "utility/xbuf.h"
#include "utility/xbuf.h"
xbuf::xbuf(const uint16_t segSize) : _head(nullptr), _tail(nullptr), _used(0), _free(0), _offset(0)
{

View File

@ -148,6 +148,4 @@ class xbuf: public Print
};
#include "utility/xbuf_Impl.h"
#endif // xbuf_h