FIAP (IEEE1888) library

Dependents:   Fetch_IEEE1888_Storage IEEE1888_MULTI_SENSOR_GW

Fork of FiapV2 by Yasushi TAUCHI

fiap.h

Committer:
strysd
Date:
2013-02-24
Revision:
14:a9ec0e6e22c8
Parent:
13:13cceccf6bfb
Child:
15:3bd6f70e57e2

File content as of revision 14:a9ec0e6e22c8:

//  IEEE1888 / FIAP Uploader Library for Arduino
//
//  2011/09/19 ver.1   H.Inoue & H.Ochiai
//  2011/12/31 Ver.1 for mbed Y.Tauchi
//  2013/02 inherited repository by S.Yoshida

// --------- FIAP.h  ---------
#ifndef MBED_FIAP_H
#define MBED_FIAP_H

#include "mbed.h"
#include "HTTPClient.h"

// return code of post method
#define FIAP_UPLOAD_OK       0  // Succeeded
#define FIAP_UPLOAD_CONNFAIL 1  // Connection faild (Socket I/O error)
#define FIAP_UPLOAD_DNSERR   2  // DNS error
#define FIAP_UPLOAD_HTTPERR  3  // HTTP Server error (The response was not "200 OK")
#define FIAP_UPLOAD_FIAPERR  4  // FIAP Server error

// use fetch_last_data(struct fiap_element* v, unsigned int esize) if true
#define USE_FETCH_MULTI  false

// use fetch_last_data(struct fiap_element* v) if true, but it seems to be broken
#define USE_FETCH_ONLY_1 false

/** fiap_element
 *@param char*     cid    Point ID
 *@param char*     value  data
 *@param uint16_t  year   nnnn
 *@param uint8_t   month  1-12
 *@param uint8_t   day    1-31
 *@param uint8_t   hour   0-23
 *@param uint8_t   minute 0-59
 *@param uint8_t   second 0-59
 *@param char*     timezone -nn:nn, +nn:nn
 */
struct fiap_element {
    char* cid;
    char* value;
    uint16_t year;
    uint8_t month;
    uint8_t day;
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
    char* timezone;
};

/** FIAP Class */
class FIAP {
public:
    /** Create fiap object
     * @param Storage FIAP Storage Addrees
     * @param _use_fetch use fetch mode if true, write mode if false
     */
    FIAP(char Storage[], bool _use_fetch);
    FIAP(char Storage[]);
    FIAP();

    /** Set Storage URL
     * @param Storage FIAP Storage Addrees
     */
    void setStorage(char Storage[]);

    /** post
     * @param v data vaule
     * @param esize  number of data
     */
    int post(struct fiap_element* v, unsigned int esize);

    /** fetch_maximum 
     * @param cid Point ID s
     * @param v Return Values
     * @param esize <=2
     * @return network_error
     */
    int fetch_last_data(struct fiap_element* v, unsigned int esize);
    int fetch_last_data(struct fiap_element* v);

    /** debug_mode
     *  Output XML and Error
     */
    bool debug_mode;
    
private:
    bool _use_fetch;//use fetch mode if true, write mode if false
    char _fiap_storage[100];//FIAP Storage Addrees
    //char _fiap_id_prefix[100];
    char _soap_header[256];
    char _soap_footer[256];
    char _soap_action[32];
    char _soap_text[2000];
    char _uuid[37];
    void xml_initialize(void);
    void generateUUID();
    char* HTTPStatusText(HTTPResult r);
    void myprintf(char*);
};

#endif