Sfoglia il codice sorgente

Move WiFi credentials to variables

No more creds.c

Set PICOWOTA_WIFI_SSID/PICOWOTA_WIFI_PASS environment variables or
CMake variables.
Brian Starkey 2 anni fa
parent
commit
321c246425
3 ha cambiato i file con 36 aggiunte e 5 eliminazioni
  1. 21
    1
      CMakeLists.txt
  2. 0
    2
      creds.c
  3. 15
    2
      main.c

+ 21
- 1
CMakeLists.txt Vedi File

@@ -35,7 +35,6 @@ pico_sdk_init()
35 35
 
36 36
 add_executable(picowota
37 37
 	main.c
38
-	creds.c
39 38
 	tcp_comm.c
40 39
 )
41 40
 
@@ -72,6 +71,27 @@ target_link_libraries(picowota
72 71
 	picowota_reboot
73 72
 )
74 73
 
74
+if (DEFINED ENV{PICOWOTA_WIFI_SSID} AND (NOT PICOWOTA_WIFI_SSID))
75
+	set(PICOWOTA_WIFI_SSID $ENV{PICOWOTA_WIFI_SSID})
76
+	message("Using PICOWOTA_WIFI_SSID from environment ('${PICOWOTA_WIFI_SSID}')")
77
+endif ()
78
+
79
+if (DEFINED ENV{PICOWOTA_WIFI_PASS} AND (NOT PICOWOTA_WIFI_PASS))
80
+	set(PICOWOTA_WIFI_PASS $ENV{PICOWOTA_WIFI_PASS})
81
+	message("Using PICOWOTA_WIFI_PASS from environment (hidden)")
82
+endif ()
83
+
84
+if ((NOT PICOWOTA_WIFI_SSID) OR (NOT PICOWOTA_WIFI_PASS))
85
+        message(FATAL_ERROR
86
+		"WiFi SSID/Pass not set, please set PICOWOTA_WIFI_SSID/PICOWOTA_WIFI_PASS."
87
+	)
88
+endif ()
89
+
90
+# TODO: This causes a full rebuild if they change, configure_file might
91
+# be better.
92
+target_compile_definitions(picowota PUBLIC PICOWOTA_WIFI_SSID=${PICOWOTA_WIFI_SSID})
93
+target_compile_definitions(picowota PUBLIC PICOWOTA_WIFI_PASS=${PICOWOTA_WIFI_PASS})
94
+
75 95
 # Provide a helper to build a standalone target
76 96
 function(picowota_build_standalone NAME)
77 97
 	get_target_property(PICOWOTA_SRC_DIR picowota SOURCE_DIR)

+ 0
- 2
creds.c Vedi File

@@ -1,2 +0,0 @@
1
-const char *wifi_ssid = "YourNetworkName";
2
-const char *wifi_pass = "YourPassw0rd";

+ 15
- 2
main.c Vedi File

@@ -40,8 +40,21 @@
40 40
 #define DBG_PRINTF(...) { }
41 41
 #endif
42 42
 
43
-extern const char *wifi_ssid;
44
-extern const char *wifi_pass;
43
+#define QUOTE(name) #name
44
+#define STR(macro) QUOTE(macro)
45
+
46
+#ifndef PICOWOTA_WIFI_SSID
47
+#warning "PICOWOTA_WIFI_SSID not defined"
48
+#else
49
+const char *wifi_ssid = STR(PICOWOTA_WIFI_SSID);
50
+#endif
51
+
52
+#ifndef PICOWOTA_WIFI_PASS
53
+#warning "PICOWOTA_WIFI_PASS not defined"
54
+#else
55
+const char *wifi_pass = STR(PICOWOTA_WIFI_PASS);
56
+#endif
57
+
45 58
 critical_section_t critical_section;
46 59
 
47 60
 #define EVENT_QUEUE_LENGTH 8

Loading…
Annulla
Salva