创建目录,挂载块设备"font"到 DFS 目录/fal/test中,尝试写文件(未成功)
This commit is contained in:
parent
43846001be
commit
eef5be42cd
|
@ -53,4 +53,5 @@ for item in list:
|
|||
group = group + SConscript(os.path.join(item, 'SConscript'))
|
||||
|
||||
Return('group')
|
||||
```
|
||||
```
|
||||
[RSOC问题汇总连接](https://docs.qq.com/doc/DY2VrUlpuRWlRUkdI)
|
31
Day5/mqtt.c
31
Day5/mqtt.c
|
@ -6,6 +6,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "aht10.h"
|
||||
#include <dfs_posix.h>
|
||||
|
||||
char DEMO_PRODUCT_KEY[IOTX_PRODUCT_KEY_LEN + 1] = {0};
|
||||
char DEMO_DEVICE_NAME[IOTX_DEVICE_NAME_LEN + 1] = {0};
|
||||
|
@ -49,6 +50,7 @@ static void example_message_arrive(void *pcontext, void *pclient, iotx_mqtt_even
|
|||
/* print topic name and topic message */
|
||||
EXAMPLE_TRACE("Message Arrived:");
|
||||
rt_pin_mode(GPIO_LED_R, PIN_MODE_OUTPUT);
|
||||
//topic_info->payload 为发送的内容,可以据此设置命令
|
||||
if(rt_pin_read(GPIO_LED_R) == PIN_HIGH)
|
||||
{
|
||||
// rt_kprintf("LED_R should be ON\n");
|
||||
|
@ -94,13 +96,40 @@ static int example_subscribe(void *handle)
|
|||
HAL_Free(topic);
|
||||
return 0;
|
||||
}
|
||||
void make_file(char *String)
|
||||
{
|
||||
//文件描述符
|
||||
int fd;
|
||||
|
||||
char tmp[256];
|
||||
//用只写方式打开文件,如果没有该文件,则创建一个文件
|
||||
fd = open("/fal/test/Data.txt", O_APPEND | O_CREAT);
|
||||
|
||||
//如果打开成功
|
||||
if (fd >= 0)
|
||||
{
|
||||
//写入文件
|
||||
write(fd, String, sizeof(String));
|
||||
|
||||
rt_kprintf("Write done.\n");
|
||||
|
||||
//关闭文件
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("File Open Fail.\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
char tmp[256];
|
||||
int cnt = 0;
|
||||
void tmp_payload(void)
|
||||
{
|
||||
// 读取温湿度值
|
||||
Humi = aht10_read_humidity(Dev);
|
||||
Temp = aht10_read_temperature(Dev);
|
||||
sprintf(tmp, "Temp:%f ; Humi:%f ; Count: %d", Temp, Humi,++cnt);
|
||||
make_file(tmp);
|
||||
sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f}}", Temp, Humi);
|
||||
rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp);
|
||||
return;
|
||||
|
|
|
@ -84,7 +84,39 @@ static int onboard_fal_mount(void)
|
|||
LOG_D("You should create a filesystem on the block device first!");
|
||||
}
|
||||
}
|
||||
|
||||
int ret;
|
||||
|
||||
/* 创建目录 */
|
||||
ret = mkdir("/fal/test", 0x777);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* 创建目录失败 */
|
||||
rt_kprintf("dir error!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 创建目录成功 */
|
||||
rt_kprintf("mkdir ok!\n");
|
||||
}
|
||||
/* 挂载块设备"font"到 DFS 目录/fal/test中 */
|
||||
if (dfs_mount("font", "/fal/test", "elm", 0, 0) == 0)
|
||||
{
|
||||
LOG_I("font initialized!");
|
||||
}
|
||||
else
|
||||
{
|
||||
dfs_mkfs("elm", "font");
|
||||
if (dfs_mount("font", "/fal/test", "elm", 0, 0) == 0)
|
||||
{
|
||||
LOG_I("font initialized!");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("Failed to initialize font!");
|
||||
LOG_D("You should create a filesystem(font) on the block device first!");
|
||||
}
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
#endif /*BSP_USING_FLASH_FATFS*/
|
||||
|
|
Loading…
Reference in New Issue