HTTP method POST and GET for IoT application demo

<< Click to Display Table of Contents >>

Navigation:  Tips & Tricks > Boards >

HTTP method POST and GET for IoT application demo

Previous pageReturn to chapter overviewNext page

Overview

This topic demonstrate how to upload data via HTTP POST and download via HTTP GET to IoT server, ThingSpeck. The interface command used by this demo listed below:

1. Upload data (POST method)

Server: api.thingspeak.com
Action: /update
Parameter field:
i.api_key = <your_api_key>  ; Note: API Key will provided when create ThingSpeak channel.
ii.field1=<Data #1> ; Data field1. For this demo, field1 is  a running number of ADC value to upload.
iii.field2=<Data #2>; Data field2. For this demo, field2 is  a Voltage value reading from LDR sensor.

1. Download data (GET method)

Server: api.thingspeak.com
Request: /channels/<your_channel>/feeds.csv?results=5     ;Note: download 5 latest data in CSV format.

 

Note: You have to create your own Channel for Testing.

Hardware Setup required for demonstration

NUCLEO-F429ZI board

webserver_manual_configure_hardware_setup

Waijung Blocks Setup

Target Setup block

webserver_manual_configure_block_targetsetup

 

Ethernet Setup

Ethernet Link Setup

webserver_manual_configure_block_ethernetlink_setup

Ethernet Application Setup

webserver_manual_configure_block_ethernetapp_setup

 

 Make sure IP address did not conflict with other device in the network.

Demo model file

The demo file for NUCLEO-F429ZI board located in directory "targets\stm32f4_target\stm32f4\demo\boards\nucleo_f429zi".

Model file: http_method_post_thingspeak_demo.mdl

http_client_model

Post data trigger

The Processing time (CPU load) of HTTP POST and GET cannot fitted into one sample time (10ms), so the block designed to work as Non-Blocking mode.
A non-zero value to "Trig" input port will start the process. Output Status port will indicate the operation state, BUSY, SUCCESS or FAILED.
Turn on delay time required for network initialization.

LED status

The demo use 3 On-board LED for indicates POST data operation status.

LED1 (Green), Normal is blinking 200ms period indicates software is running.
LED2 (Blue), Flashing (turn on for 1 time step) indicate POST operation SUCCESS.
LED3 (Red), Flashing (turn on for 1 time step) indicate POST operation FAILED.

UART Debug message

On-board ST-Link of NUCLEO board used for programming/debugging, and also provide USB-Virtual COM port. This demo transmit the Response data to UART3 (PD8/PD9) which will be redirected to USB virtual COM port, the response data can be captured by Serial terminal software.

Testing

Run Serial Terminal Software (Putty), with baud rate setting 115200.

http_client_testing_putty

The display Chart on ThingSpeak

http_client_testing_chart