Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/utils/projectGeneration/projectZephyr.mts
Original file line number Diff line number Diff line change
Expand Up @@ -422,31 +422,31 @@ async function generateWifiMainC(
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <errno.h>

// Local includes
#include "http.h"
#include "json_definitions.h"
#include "ping.h"
#include "wifi.h"
#include "wifi_info.h"

#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(wifi_example);

/* HTTP server to connect to */
const char HTTP_HOSTNAME[] = "google.com";
const char HTTP_PATH[] = "/";
const char JSON_HOSTNAME[] = "jsonplaceholder.typicode.com";
const char JSON_GET_PATH[] = "/posts/1";
const char HTTP_HOSTNAME[] = "google.com";
const char HTTP_PATH[] = "/";
const char JSON_HOSTNAME[] = "jsonplaceholder.typicode.com";
const char JSON_GET_PATH[] = "/posts/1";
const char JSON_POST_PATH[] = "/posts";

int main(void)
{
printk("Starting wifi example on %s\\n", CONFIG_BOARD_TARGET);

wifi_connect(WIFI_SSID, WIFI_PSK);
// give DHCP a bit of time
k_sleep(K_SECONDS(3));

// Ping Google DNS 8 times
printk("Pinging 8.8.8.8 to demonstrate connection:\\n");
Expand All @@ -459,36 +459,43 @@ int main(void)
// Using https://jsonplaceholder.typicode.com/ to demonstrate GET and POST requests with JSON
struct json_example_object get_post_result;
int json_get_status = json_get_example(JSON_HOSTNAME, JSON_GET_PATH, &get_post_result);

if (json_get_status < 0)
{
LOG_ERR("Error in json_get_example");
} else {
}
else
{
printk("Got JSON result:\\n");
printk("Title: %s\\n", get_post_result.title);
printk("Body: %s\\n", get_post_result.body);
printk("User ID: %d\\n", get_post_result.userId);
printk("ID: %d\\n", get_post_result.id);
}

k_sleep(K_SECONDS(1));

struct json_example_object new_post_result;
struct json_example_payload new_post = {
.body = "RPi",
.title = "Pico",
.userId = 199
};
.userId = 199};

json_get_status = json_post_example(JSON_HOSTNAME, JSON_POST_PATH, &new_post, &new_post_result);

if (json_get_status < 0)
{
LOG_ERR("Error in json_post_example");
} else {
}
else
{
printk("Got JSON result:\\n");
printk("Title: %s\\n", new_post_result.title);
printk("Body: %s\\n", new_post_result.body);
printk("User ID: %d\\n", new_post_result.userId);
printk("ID: %d\\n", new_post_result.id);
}

k_sleep(K_SECONDS(1));

return 0;
Expand Down
Loading
Loading