@@ -422,31 +422,31 @@ async function generateWifiMainC(
422422 * SPDX-License-Identifier: Apache-2.0
423423 */
424424
425- #include <zephyr/kernel.h>
426- #include <zephyr/logging/log.h>
427- #include <errno.h>
428-
429- // Local includes
430425#include "http.h"
431426#include "json_definitions.h"
432427#include "ping.h"
433428#include "wifi.h"
434429#include "wifi_info.h"
435430
431+ #include <zephyr/kernel.h>
432+ #include <zephyr/logging/log.h>
433+
436434LOG_MODULE_REGISTER(wifi_example);
437435
438436/* HTTP server to connect to */
439- const char HTTP_HOSTNAME[] = "google.com";
440- const char HTTP_PATH[] = "/";
441- const char JSON_HOSTNAME[] = "jsonplaceholder.typicode.com";
442- const char JSON_GET_PATH[] = "/posts/1";
437+ const char HTTP_HOSTNAME[] = "google.com";
438+ const char HTTP_PATH[] = "/";
439+ const char JSON_HOSTNAME[] = "jsonplaceholder.typicode.com";
440+ const char JSON_GET_PATH[] = "/posts/1";
443441const char JSON_POST_PATH[] = "/posts";
444442
445443int main(void)
446444{
447445 printk("Starting wifi example on %s\\n", CONFIG_BOARD_TARGET);
448446
449447 wifi_connect(WIFI_SSID, WIFI_PSK);
448+ // give DHCP a bit of time
449+ k_sleep(K_SECONDS(3));
450450
451451 // Ping Google DNS 8 times
452452 printk("Pinging 8.8.8.8 to demonstrate connection:\\n");
@@ -459,36 +459,43 @@ int main(void)
459459 // Using https://jsonplaceholder.typicode.com/ to demonstrate GET and POST requests with JSON
460460 struct json_example_object get_post_result;
461461 int json_get_status = json_get_example(JSON_HOSTNAME, JSON_GET_PATH, &get_post_result);
462+
462463 if (json_get_status < 0)
463464 {
464465 LOG_ERR("Error in json_get_example");
465- } else {
466+ }
467+ else
468+ {
466469 printk("Got JSON result:\\n");
467470 printk("Title: %s\\n", get_post_result.title);
468471 printk("Body: %s\\n", get_post_result.body);
469472 printk("User ID: %d\\n", get_post_result.userId);
470473 printk("ID: %d\\n", get_post_result.id);
471474 }
475+
472476 k_sleep(K_SECONDS(1));
473477
474478 struct json_example_object new_post_result;
475479 struct json_example_payload new_post = {
476480 .body = "RPi",
477481 .title = "Pico",
478- .userId = 199
479- };
482+ .userId = 199};
480483
481484 json_get_status = json_post_example(JSON_HOSTNAME, JSON_POST_PATH, &new_post, &new_post_result);
485+
482486 if (json_get_status < 0)
483487 {
484488 LOG_ERR("Error in json_post_example");
485- } else {
489+ }
490+ else
491+ {
486492 printk("Got JSON result:\\n");
487493 printk("Title: %s\\n", new_post_result.title);
488494 printk("Body: %s\\n", new_post_result.body);
489495 printk("User ID: %d\\n", new_post_result.userId);
490496 printk("ID: %d\\n", new_post_result.id);
491497 }
498+
492499 k_sleep(K_SECONDS(1));
493500
494501 return 0;
0 commit comments