diff options
author | 2019-04-10 00:49:58 +0300 | |
---|---|---|
committer | 2019-04-10 00:49:58 +0300 | |
commit | 8b65cf403229f3839c791ae1b7f8d2bbc266772b (patch) | |
tree | fcfa6555c188c2c6744c2d63ef41801786c4c988 | |
parent | 66dea0ba9ac413819059606c748cb5446ccbb5d1 (diff) | |
download | usurpation-8b65cf403229f3839c791ae1b7f8d2bbc266772b.tar.gz usurpation-8b65cf403229f3839c791ae1b7f8d2bbc266772b.tar.bz2 usurpation-8b65cf403229f3839c791ae1b7f8d2bbc266772b.zip |
device: make ssid and password easy to modify
The SSID and PSK the device is going to attempt connecting
can now be changed with a recompiliation by adjusting the
"ssid" and "password" build options for meson with e.g.
meson configure -Dssid=realssid -Dpassword=actualpsk
Default SSID and PSK are included to otherwise allow
test builds.
this closes ticket 26.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
-rw-r--r-- | meson_options.txt | 2 | ||||
-rw-r--r-- | src/device/main.ino | 4 | ||||
-rw-r--r-- | src/device/meson.build | 41 |
3 files changed, 41 insertions, 6 deletions
diff --git a/meson_options.txt b/meson_options.txt index 446dc5c..7cc6df4 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,5 @@ option('tests', type : 'boolean', value : false, description : 'Enable building and running tests') option('fwbuild', type : 'boolean', value : false, description : 'Enable building the firmware image for the wearable') option('fwflash', type : 'boolean', value : false, description : 'Automatically flash the firmware with freshly built fw image (requires fwbuild)') +option('ssid', type : 'string', value : 'ssid', description : 'wireless ssid to compile into the firmware (no effect without fwbuild') +option('password', type : 'string', value : 'password', description : 'wireless password to compile into the firmware (no effect without fwbuild') diff --git a/src/device/main.ino b/src/device/main.ino index eb5d122..28e8dae 100644 --- a/src/device/main.ino +++ b/src/device/main.ino @@ -44,9 +44,11 @@ static void blink_led(const int pin, const int ontime, const int offtime); void setup(void) { + extern const char * const ssid; + extern const char * const password; pinMode(internal_led, OUTPUT); toggle_led(internal_led); - wifi_connect("ssid", "password", 1, internal_led); + wifi_connect(ssid, password, 1, internal_led); discover_client(); } diff --git a/src/device/meson.build b/src/device/meson.build index 9bb9b69..b3df933 100644 --- a/src/device/meson.build +++ b/src/device/meson.build @@ -1,17 +1,48 @@ fw_image = 'fw.bin' +decl = 'const char * const %s = "%s";\n' if get_option('fwbuild') espmake = find_program('espmake') + printf = find_program('printf') + cat = find_program('cat') + cp = find_program('cp') - sourcedir = meson.current_source_dir() fw_filenames = ['main.ino'] - fw_sources = files(fw_filenames) + fw_true_sources = files(fw_filenames) + + sourcedir = meson.current_source_dir() + builddir = meson.current_build_dir() + + fw_conf_ssid = custom_target('fw_conf_ssid', + output : ['conf_ssid'], + capture : true, + command : [printf, decl, 'ssid', get_option('ssid')]) + + fw_conf_pass = custom_target('fw_conf_pass', + output : ['conf_pass'], + capture : true, + command : [printf, decl, 'password', get_option('password')]) + + fw_conf = custom_target('fw_conf', + output : ['conf.c'], + capture : true, + command : [cat, fw_conf_ssid, fw_conf_pass]) + + fw_sources = custom_target('fw_sources', + output : fw_filenames, + input : fw_true_sources, + command : [cp, '@INPUT@', '@OUTDIR@/']) + fw = custom_target('fw', output : fw_image, - input : fw_sources, - command : [espmake, '-C', sourcedir, '&&', 'cp', '/tmp/mkESP/main_d1_mini/main.bin', '@OUTDIR@/' + fw_image], install : true, install_dir : resource_dir) + input : [fw_sources, fw_conf], + command : [espmake, '-C', builddir, '&&', cp, '/tmp/mkESP/main_d1_mini/main.bin', '@OUTDIR@/' + fw_image], + install : true, + install_dir : resource_dir) if get_option('fwflash') esptool = find_program('esptool.py') - run_target('flash_fw', depends : fw, command : [esptool, 'write_flash', '0x0', fw]) + run_target('flash_fw', + depends : fw, + command : [esptool, 'write_flash', '0x0', fw]) endif endif |