Ambient library. It provides "set" function to set data to a packet and "send" function to send the packet to the Ambient server. It also provides "bulk_send" function to send multiple data. (Japanese: IoT用のクラウドサービス「Ambient」のデーター送信ライブラリーです。Ambientはマイコンから送られたセンサーデーターを受信し、蓄積し、可視化(グラフ化)します。http://ambidata.io)

Dependents:   AmbientExampleSITB AmbientHeartRateMonitor AmbientHeartBeat AmbientExampleSITB_ws ... more

Embed: (wiki syntax)

« Back to documentation index

Ambient Class Reference

Ambient Class Reference

Ambient class to send data to Ambient service. More...

#include <Ambient.h>

Public Member Functions

 Ambient (void)
 Create Ambient instance.
bool init (unsigned int channelId, const char *writeKey, TCPSocketConnection *s, int dev=0)
 Initialize the instance.
bool set (int field, char *data)
 Set data on field-th field of payload.
bool set (int field, int data)
 Set data on field-th field of payload.
bool set (int field, double data)
 Set data on field-th field of payload.
bool clear (int field)
 Clear data on field-th field of payload.
bool send (void)
 Send data to Ambient.
int bulk_send (char *buf)
 Send bulk data to Ambient.

Detailed Description

Ambient class to send data to Ambient service.

Exsample:

 #include "mbed.h"
 #include "EthernetInterface.h"
 #include "Ambient.h"
 #include "HDC1000.h"
 
 unsigned int channelId = 100;
 const char* writeKey = "ライトキー";
 Ambient ambient;
 
 HDC1000      hdc1000(p9,p10);
 
 int main() {
     printf("start\r\n");
 
     EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
 
     TCPSocketConnection socket;
     ambient.init(channelId, writeKey, &socket);
 
     printf("Ambient send to ch: %d\r\n", channelId);
 
     while (true) {
         float temp, humid;
         char tempbuf[12], humidbuf[12];
 
         hdc1000.get();
         temp = hdc1000.temperature();
         humid = hdc1000.humidity();
 
         sprintf(tempbuf, "%2.1f", temp);
         ambient.set(1, tempbuf);
         sprintf(humidbuf, "%2.0f", humid);
         ambient.set(2, humidbuf);
         printf("Temp: %s C, Humid: %s %%\r\n", tempbuf, humidbuf);
         
         ambient.send();
         
         wait(30.0);
     }
 }

Definition at line 62 of file Ambient.h.


Constructor & Destructor Documentation

Ambient ( void   )

Create Ambient instance.

Definition at line 28 of file Ambient.cpp.


Member Function Documentation

int bulk_send ( char *  buf )

Send bulk data to Ambient.

Parameters:
bufpointer to the data buffer
Returns:
the number of written bytes on success (>=0) -1 on failure

Definition at line 177 of file Ambient.cpp.

bool clear ( int  field )

Clear data on field-th field of payload.

Parameters:
fieldindex of payload (1 to 8)
Returns:
true on success, false on failure

Definition at line 90 of file Ambient.cpp.

bool init ( unsigned int  channelId,
const char *  writeKey,
TCPSocketConnection *  s,
int  dev = 0 
)

Initialize the instance.

Parameters:
channelIdInitialize the Ambient instance with channelId.
writeKeyand writeKey
sand pointer to socket
Returns:
true on success, false on failure

Definition at line 32 of file Ambient.cpp.

bool send ( void   )

Send data to Ambient.

Returns:
true on success, false on failure

Definition at line 101 of file Ambient.cpp.

bool set ( int  field,
double  data 
)

Set data on field-th field of payload.

Parameters:
fieldindex of payload (1 to 8)
datadata
Returns:
true on success, false on failure
bool set ( int  field,
char *  data 
)

Set data on field-th field of payload.

Parameters:
fieldindex of payload (1 to 8)
datadata
Returns:
true on success, false on failure
bool set ( int  field,
int  data 
)

Set data on field-th field of payload.

Parameters:
fieldindex of payload (1 to 8)
datadata
Returns:
true on success, false on failure