1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/notrynohigh-BabyOS

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Это зеркальный репозиторий, синхронизируется ежедневно с исходного репозитория.
Клонировать/Скачать
utc_main.c 2.5 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
notrynohigh Отправлено 10 месяцев назад 0de069c
/**
* \file kv_main.c
* \brief
* \version 0.1
* \date 2022-10-29
* \author notrynohigh (notrynohigh@outlook.com)
*
* Copyright (c) 2020 by notrynohigh. All Rights Reserved.
*/
#include <time.h>
#include "../port.h"
#include "b_os.h"
int httpfd = -1;
void ntp_test()
{
bUTC_DateTime_t tm;
bUTC_t now_utc = bUTC_GetTime();
bUTC2Struct(&tm, now_utc, 8);
b_log("%d-%02d-%02d %02d:%02d:%02d %02d\r\n", tm.year, tm.month, tm.day, tm.hour, tm.minute,
tm.second, tm.week);
b_log_w(":::::%d\r\n", bGetFreeSize());
if (now_utc > 1711855508)
{
bHttpRequest(httpfd, B_HTTP_GET,
"http://restapi.amap.com/v3/weather/"
"weatherInfo?city=440300&key=2ecb62606e0682a50cae3ade6b30c3b1",
NULL, NULL);
}
}
void HttpCb(bHttpEvent_t event, void *param, void *arg)
{
if (event == B_HTTP_EVENT_RECV_DATA)
{
bHttpRecvData_t *dat = (bHttpRecvData_t *)param;
if (dat->pdat != NULL && dat->len > 0)
{
b_log("%s", dat->pdat);
char *pstr = strstr(dat->pdat, "\r\n\r\n");
if (pstr != NULL)
{
cJSON *root = cJSON_Parse(pstr);
if (root)
{
cJSON *lives = cJSON_GetObjectItem(root, "lives");
if (lives != NULL && lives->type == cJSON_Array)
{
lives = cJSON_GetArrayItem(lives, 0);
cJSON *weather = cJSON_GetObjectItem(lives, "weather");
cJSON *temperature = cJSON_GetObjectItem(lives, "temperature");
cJSON *humidity = cJSON_GetObjectItem(lives, "humidity");
b_log("\r\n\r\nweather: %s\r\n", weather->valuestring);
b_log("\r\ntemperature:%s℃\r\n", temperature->valuestring);
b_log("\r\nhumidity:%s%%\r\n", humidity->valuestring);
}
cJSON_Delete(root);
}
}
}
if (dat)
{
if (dat->release)
{
dat->release(dat->pdat);
}
}
}
}
void bMallocFailedHook()
{
b_log_e("=========================\r\n");
}
int main()
{
port_init();
bInit();
bTcpipSrvInit();
bSntpStart(60 * 60);
httpfd = bHttpInit(HttpCb, NULL);
while (1)
{
bExec();
BOS_PERIODIC_TASK(ntp_test, 1000 * 10);
}
return 0;
}

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/notrynohigh-BabyOS.git
git@gitlife.ru:oschina-mirror/notrynohigh-BabyOS.git
oschina-mirror
notrynohigh-BabyOS
notrynohigh-BabyOS
V8.5.0