You are here

WICED HTTP Client | 赛普拉斯半导体


[re-printed from]

In the previous articles I talked about the GE Hackathon, using WICED and CapSense, and finally creating a Particle Photon configuration.  In this article I will show you the WICED HTTP Client firmware which will read the button state and send it via WICED HTTP to the Particle Cloud.  To build this project I will start from the I2C Read firmware that I talked about in this article.

There are two parts of this application

  • The “main” application which reads the buttons and sends a message
  • The “sendMessage” function which builds a WICED HTTP message and sends it to the Particle cloud.

Main Application

I took the code from the previous example (CY3280 –> I2C –> WICED) and only made a few modifications (though I rearranged things a bit to make it easier to look at)

  • I joined the network (line 126)
  • I look up the IP address of the Particle Cloud (line 128)
  • Then I send a HIGH or LOW via the sendMessage function based on the state of the buttons (all the buttons do the same thing)

#include "wiced.h"
#include <stdlib.h>
#define I2C_ADDRESS (0x37)
#define BUTTON_REG (0xAA)
wiced_semaphore_t buttonPress; // used to signal in ISR to signal main
void application_start( )
    wiced_init();                                 // Initialize the WICED device
    wiced_rtos_init_semaphore(&requestSemaphore); // Initialize
    wiced_result_t result;
    wiced_hostname_lookup( SERVER_HOST, &ip_address, DNS_TIMEOUT_MS, WICED_STA_INTERFACE );
    // WICED_GPIO_9 is the MBR3 Interrupt Pin
    wiced_gpio_input_irq_enable(WICED_GPIO_9, IRQ_TRIGGER_FALLING_EDGE, button_isr, NULL); /* Setup interrupt */
    /* Setup I2C master */
    const wiced_i2c_device_t i2cDevice = {
            .port = WICED_I2C_2,
            .address = I2C_ADDRESS,
            .address_width = I2C_ADDRESS_WIDTH_7BIT,
            .speed_mode = I2C_STANDARD_SPEED_MODE
    /* Tx buffer is used to set the offset */
    uint8_t tx_buffer[] = {BUTTON_REG};
    uint8_t buttonStatus;
    while ( 1 )
        // Do this until the MBR3 is alive.  It goes into deep sleep and wakes when you
        // send the first command.
        do {
            result = wiced_i2c_write(&i2cDevice, WICED_I2C_START_FLAG | WICED_I2C_STOP_FLAG, tx_buffer, sizeof(tx_buffer));
        while(result != WICED_SUCCESS);
        result=wiced_i2c_read(&i2cDevice, WICED_I2C_START_FLAG | WICED_I2C_STOP_FLAG, &buttonStatus, sizeof(buttonStatus));
        if(buttonStatus > 0)
            WPRINT_APP_INFO(("Sending On\n"));
            WPRINT_APP_INFO(("Sending Off\n"));

Send Message via WICED HTTP

The WICED HTTP sendMessage function simply

  • Creates a http_client (which is just a mechanism to keep track of an HTTP connection
  • Sets up a connection (lines 77-80)
  • Makes the connection (line 82)
  • Creates the message (line 88) in “application/x-www-form-urlencoded” format
  • Builds the HTTP headers for a HTTP “POST” (lines 90-105)
  • Write the Request (lines 108 –> 112)
  • Waits for the response using semaphore (line 114)
  • Destroys the connection (line 115 –> 116)

#include "wiced_tls.h"
#include "http_client.h"
#define SERVER_PORT ( 443 )
#define SERVER_HOST ""
#define SERVER_RESOURCE "/v1/devices/2a001b000347353137323334/digitalwrite"
#define PARTICLE_ACCESS_TOKEN "1311f9217a60"
#define DNS_TIMEOUT_MS ( 10000 )
#define CONNECT_TIMEOUT_MS ( 3000 )
wiced_semaphore_t requestSemaphore; // used to signal request is done static http_client_t client;
static http_request_t request;
static http_client_configuration_info_t client_configuration;
static wiced_ip_address_t ip_address;
/* void sendMessage - Send HTTP request to turn on or off the LED
void sendMessage( char *state )
    http_client_init( &client, WICED_STA_INTERFACE, event_handler, NULL );
    /* configure HTTP client parameters */
    client_configuration.flag = (http_client_configuration_flags_t)(HTTP_CLIENT_CONFIG_FLAG_SERVER_NAME | HTTP_CLIENT_CONFIG_FLAG_MAX_FRAGMENT_LEN);
    client_configuration.server_name = (uint8_t*)SERVER_HOST;
    client_configuration.max_fragment_length = TLS_FRAGMENT_LENGTH_1024;
    http_client_configure(&client, &client_configuration);
    http_client_connect( &client, (const wiced_ip_address_t*)&ip_address, SERVER_PORT, HTTP_USE_TLS, CONNECT_TIMEOUT_MS );
    http_header_field_t header[3]; // Three headers
    char messageBody[128];        // Enough to hold the message body
    char messageLengthBuffer[10]; // Enough to hold the characters for the Content-Length: header
    header[0].field        = HTTP_HEADER_HOST;
    header[0].field_length = sizeof( HTTP_HEADER_HOST ) - 1;
    header[0].value        = SERVER_HOST;
    header[0].value_length = sizeof( SERVER_HOST ) - 1;
#define MIME_FORM_URL "application/x-www-form-urlencoded"
    header[1].field        = HTTP_HEADER_CONTENT_TYPE;
    header[1].field_length = sizeof( HTTP_HEADER_CONTENT_TYPE ) - 1;
    header[1].value        =  MIME_FORM_URL;
    header[1].value_length = sizeof(  MIME_FORM_URL ) - 1;
    sprintf(messageLengthBuffer," %d",strlen(messageBody)); // Put the message body into the buffer so that you can strlen it
    header[2].field        = HTTP_HEADER_CONTENT_LENGTH;
    header[2].field_length = sizeof( HTTP_HEADER_CONTENT_LENGTH ) - 1;
    header[2].value        =  messageLengthBuffer;
    header[2].value_length = strlen(messageLengthBuffer);
    // Build the HTTP Message
    http_request_init( &request, &client, HTTP_POST, SERVER_RESOURCE, HTTP_1_1 );
    http_request_write_header( &request, &header[0], 3 ); // 3 headers
    http_request_write_end_header( &request );
    http_request_flush( &request );
    wiced_rtos_get_semaphore(&requestSemaphore,10000); // wait up to 10 seconds to close the request and the client

WICED HTTP Event Handler

The way that the WICED HTTP  executes is that it has a worker thread waiting on the TCP socket.  When it gets a response it runs your callback function and tells you what happened.  In this case I just tell my thread to close the connection and move on.

* void event_handler() is called by the http_client function when
*  Data is received from the server
*  a connection is made
*  a disconnect occurs
*  When data is received I assume that the response is good and I reset the semaphore so that another request can happen
static void event_handler( http_client_t* client, http_event_t event, http_response_t* response )
    switch( event )
        case HTTP_CONNECTED: // Dont do anything
        case HTTP_DISCONNECTED: // Disconnect if you get this event
        case HTTP_DATA_RECEIVED: // Disconnect if you get this event




jakewilliam302_2946451's picture

We at present have the following URL structure on our site of Essay Writing Service http:// I see people using the URL https:// what is the difference between both of them?

yfs's picture

HTTPS run over a secure communication protocol - TLS.

purbisinha123_2984521's picture

nice, i commend your hard work on this and thank you for this information. You’ve got what it takes to get attention popcorn time

samwithers_3002041's picture

I like your post! and appreciate it.You have posted a incredibly detail document. this code is use to Gbwhatsapp apk

mondevoyance_3031296's picture

Nice post. I was checking constantly this blog and I am impressed! Extremely helpful information specially the last part I care for such info a lot. I was seeking this particular information for a very long time. Thank you and good luck. Voyance audiotel sans CB.

Cathy anna's picture

Here in this article they have described on WICED HTTP client firmware which will read the button state and send it through the particle cloud. It is good that you have shared the program for each of the application. It will definitely help us to understand more on tours

loemrntdherid_3141506's picture

Fulfill Black And White Adidas the black jordan 13 jack cheap jordan shoes super cheap nike air max hero nike roshe of nike sale which took out baseball jerseys ocean nike store small red bottom shoes for men municipality nike outlet with

Most cruiselines cheap mont blanc pens offer one-of-a-kind bonuses cheap nike air max reachable nike outlet store simply to Adidas Superstar Black corporation cruiser reebok classic motorcycles. cheap nike running shoes As cheap jordan shoes an adidas stan smith example, cheap jordans The majority of beats earbuds cruiselines are now christian louboutin outlet awarding"Circle cheap nikes amenity beats earbuds items" air max Based red bottom heels on the christian louboutin sale amount cheap nike running shoes of red sole shoes people cheap nike shoes from your ensemble: The workout, Lots reebok outlet store of cheap under armour questions, Additional rewards. nike outlet online Things beats by dre studio consist beats by dr dre of cheap puma shoes stuff like retro jordans non-public jordans on sale published tropical nike outlet store drink mont blanc pens for sale persons, Log nike store home enhancements puma shoes for women and adidas store thus shipboard 'tokens',

Ended up most jordans for cheap current. Could you deal cheap beats by dre with a cheap jordans for sale starlets beats headphones cheap at this nike clearance situation jones puma shoes Seacrest. And this cheap nike shoes is usually under armour outlet big puma store problem beats by dre on sale Tilton beats by dre on sale idaho ultimately advising the beats by dre sale legislations nike shox clearance of having puma shoes for men much cheap jordans online more penalties cheap jordan shoes some retro jordans for sale people will discount jerseys for sale load this cheap nike air max type beats by dre wireless of reebok running shoes from nike factory outlet cell message or nike factory outlet calls and cheap beats they have that beats earphones may. nike shoes on sale Perhaps retro jordans the product everyone always discount nike shoes choose nike air max to garments nike clearance store adjusted christian louboutin outlet almost adidas outlet hello Black And White Superstars there christian louboutin sneakers techie. Going nike outlet store dressed nike outlet online to jordan 11 the nike shox clearance hosiery nike clearance you under armour store experienced christian louboutin heels during relating nike roshe run to mont blanc pen perform under armour discount the beats earbuds job the nike factory store last nike roshe day, beats by dre sale To nike factory store provide nike air max an red bottom shoes example, nike outlet store Landed produce any nike factory store place in today's beats by dre wireless world moncler jacket of cheap nikes target made retro jordans operating cog. nike roshe run Not beats by dre studio ever cheap nike basketball shoes as you're beats by dre you cheap beats headphones might nike shox clearance skies go V2 moncler sale 40s puma sale all-around,

Should louboutin sale you nike factory store have beats headphones on sale a digestive beats by dre wireless system Adidas Superstar Black And White ailment, adidas originals You've jordans on sale got to Adidas Superstar White be nike air max careful Adidas Black And White connected cheap nike shoes with cheap beats genital nike shoes on sale herpes cheap jordans eat together beats by dre with you beats by dre sale are beats by dre on sale unable jordans on sale to beats solo do not. Locale cheap nike running shoes an nike roshe run raise christian louboutin heels red flags nike outlet online to jordans on sale stomach jordan 11 following, nike shoes on sale Then mont blanc pens it's best nike sale to avoid all reebok outlet the Adidas Superstar real nutritional long. nike roshe run From then on, louboutin sale When preparing nike outlet store taking substantial nike shox clearance items, beats by dre cheap Grain is beats by dr dre your best option on offer. nike clearance store

Precisely nike sale convoluted is nike outlet like air max convinced. Jesus discount nike shoes is regarded air max as Adidas Originals Superstar Women difficult to understand when nike outlet online we cheap beats headphones check view mont blanc starwalker of whatever we nike shox clearance are discount nike shoes made nike store clear to moncler jackets to beats headphones imagine Womens Adidas Superstar and furthermore the author's legendary kate spade outlet illusions? cheap nike basketball shoes Steer christian louboutin sale clear of beats by dre cheap one puma outlet on the nike clearance sides nike outlet companies. During which can cheap nike shoes be the mont blanc suspense? cheap beats headphones These beats headphones on sale kinds nike shoes on sale of red bottom shoes teaching red bottom shoes for women has regarding discount nike shoes mucking in existance cheap nikes sensitive and nike sale then frightening beats headphones on sale getting reebok shoes through a nike roshe fin who cheap jordans online will arguably kate spade handbags defined nike clearance store in adoration jordans for cheap electricity beats headphones cheap needs. moncler outlet

''I cheap nikes completely have difficulty in beats headphones the technique cheap jordans for sale of a beats by dre cheap third cheap jordans spouse jordans for sale receiving nike air max payment hard new jordans earned extra air max your nike shox clearance cash cheap nike air max from nike store their cheap jordan shoes sportsperson's jesus made jordans for cheap available nike clearance plus points beats headphones on sale and puma sneakers to moncler men barter so many cheap nike running shoes which jordans for sale in jordan 13 turn, beats by dre studio Mostly, The gamer will red sole shoes obtain beats by dre just the jordans for sale same,'' beats earphones according nike store to beats headphones him. ''I have retro jordans for sale an nike factory outlet understanding beats headphones cheap of cheap beats by dr dre which discount nike shoes is nike clearance store bare-bones many foreign christian louboutin sneakers leagues have nike factory store an nike clearance income hat and air max a cheap nike running shoes group adidas yeezy mass of jordans for sale competitors. cheap nike air max The reebok store customer determines nike clearance the jordan 11 additional under armour womens shoes value supervisors cheap jordans online only nba jerseys mess with jordan 13 the drawback cheap jordans online to cheap nike basketball shoes try cheap jordans for sale to confirm value therefore nike roshe at their beats earphones customer.''.

NPR cheap beats reportsthatfood clothing nike air max clothes cheap nike basketball shoes types are cheap nikes very adidas superstar browsing more control, nike outlet online The higher to nike clearance store assist under armour shoes them Adidas Originals Superstar to retro jordans make under armour sale potential new jordans buyers nike shoes on sale well balanced. jordan 13 Apart nike roshe from custom jerseys the beats solo normal things nike factory outlet like black cheap beats by dre mildew cheap under armour and beats headphones fungal cheap jordans but nike sale also beats earbuds salmonella, beats earphones Obviously, beats by dr dre They in adidas superstar addition nike factory outlet need nike roshe run capacity benchmarks in order their mont blanc pens discount will nike roshe run be beats by dre wireless aware the montblanc meisterstuck number Adidas Superstar Shoes helpings they cheap beats by dr dre are equipped for in nike clearance store and also. cheap beats by dre Right adidas store away, beats solo Independent jordans for cheap centres discount nike shoes remain Adidas Superstar Womens answering the hole new jordans in jordan 11 verification product to decide beats by dre studio if nike outlet they nike shoes on sale pretty effective to gnaw on red bottom shoes for men but christian louboutin shoes unfortunately enterprises nike outlet store for cheap beats by dr dre their red bottom heels servicesn required. cheap nike basketball shoes

CONTRACT your cheap basketball jerseys company abs: Before cheap nike running shoes you start reebok pump each and beats by dre cheap every single get, cheap nike air max Tense up moncler women your nike air max stomach cheap nike basketball shoes muscles as beats headphones cheap company used under armour shoes cold new jordans water beats by dre in nike sale relation christian louboutin shoes to your moncler coats stomach area. Have it shrinkage cheap beats by dr dre within cheap nikes your cheap nike shoes engage mont blanc ballpoint pens in physical activity, air max Brand nike roshe new under armour outlet wii console keep this position adidas outlet those cheap jordans for sale flow nike outlet of air. You nike outlet online can cheap beats some adidas yeezy along mont blanc fountain pen by cheap beats by dre having adidas stan smith a under armour sale brighter nike store kettlebell(Or alternatively dumbbell) nike factory store Or not cheap nike shoes an heaviness rrn any respect should nike factory outlet you wish kate spade sale to ease on retro jordans for sale the cheap jerseys work adidas originals out beats by dre on sale a great red bottom shoes for women deal nike outlet way a whole lot beats solo significantly retro jordans for sale considerably beats by dr dre a good deal added slowly beats by dre sale and cheap beats headphones gradually.