Hardware Platform(The same method applies to different hardware platforms)
Configure RW007 Software Package
Connect D1s development board to the RW007 WIFI module via SPI0
Enter pkgs —update
to update the package
After updating the package, change ALIGN
in the struct rw007_spi
struct definition in the rw007 package to rt_align
Enter the WIFI command to connect to the WIFI
Note: There are some issues may happen when simultaneously enabling the D1s board and the RW007 module, the issues may include:
xfel.exe reset
commandCheck out the HTTP-related APIs in the channel.
Look at the figure below, the last field1=0 in the [Write a Channel Feed API is the uploaded data (where 0 is not limited to numbers, the string is also feasible)
Thingspeak uses the GET protocol, here we're bringing the webclient package to upload the data
Add the webclient package
Add rt-thread/bsp/allwinner/d1s/applications/thingspeak.c
file
Replace the value that defined by the 'GET_LOCAL_URI' to your own [Write a Channel Feed API]
#include <stdio.h>
#include <webclient.h>
#define GET_LOCAL_URI "http://api.thingspeak.com/update?api_key=XXXXXXXXXXXX&field1="
static int webclient_get_smpl(const char *uri)
{
char *response = RT_NULL;
size_t resp_len = 0;
int index;
if (webclient_request(uri, RT_NULL, RT_NULL, 0, (void **)&response, &resp_len) < 0)
{
rt_kprintf("webclient send get request failed.");
return -RT_ERROR;
}
rt_kprintf("webclient send get request by simplify request interface.\n");
rt_kprintf("webclient get response data: \n");
for (index = 0; index < rt_strlen(response); index++)
{
rt_kprintf("%c", response[index]);
}
rt_kprintf("\n");
if (response)
{
web_free(response);
}
return 0;
}
static int thingspeak(void)
{
char uri[80];
srand();
int number;
while(1)
{
number = rand() % 100;
sprintf(uri, "%s%d", GET_LOCAL_URI, number);
webclient_get_smpl(uri);
rt_kprintf("random number is %d\r\n",number);
rt_thread_mdelay(20000);
}
}
MSH_CMD_EXPORT(thingspeak, thingspeak);
The program will upload the random 0~100 value of the development board to Thingspeak every 20 seconds.
After compiling, downloading, running, and connecting to WIFI, we can then use the thingspeak command to run the program.
You can also query the data through other APIs in API Keys
There are also provide the visual analysis data
Are there any ideas you'd like to share? Comment to chat with us.