Browse Source

Move WiFi credentials to variables

No more creds.c

Set PICOWOTA_WIFI_SSID/PICOWOTA_WIFI_PASS environment variables or
CMake variables.
Brian Starkey 2 years ago
parent
commit
321c246425
3 changed files with 36 additions and 5 deletions
  1. 21
    1
      CMakeLists.txt
  2. 0
    2
      creds.c
  3. 15
    2
      main.c

+ 21
- 1
CMakeLists.txt View File

35
 
35
 
36
 add_executable(picowota
36
 add_executable(picowota
37
 	main.c
37
 	main.c
38
-	creds.c
39
 	tcp_comm.c
38
 	tcp_comm.c
40
 )
39
 )
41
 
40
 
72
 	picowota_reboot
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
 # Provide a helper to build a standalone target
95
 # Provide a helper to build a standalone target
76
 function(picowota_build_standalone NAME)
96
 function(picowota_build_standalone NAME)
77
 	get_target_property(PICOWOTA_SRC_DIR picowota SOURCE_DIR)
97
 	get_target_property(PICOWOTA_SRC_DIR picowota SOURCE_DIR)

+ 0
- 2
creds.c View File

1
-const char *wifi_ssid = "YourNetworkName";
2
-const char *wifi_pass = "YourPassw0rd";

+ 15
- 2
main.c View File

40
 #define DBG_PRINTF(...) { }
40
 #define DBG_PRINTF(...) { }
41
 #endif
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
 critical_section_t critical_section;
58
 critical_section_t critical_section;
46
 
59
 
47
 #define EVENT_QUEUE_LENGTH 8
60
 #define EVENT_QUEUE_LENGTH 8

Loading…
Cancel
Save