Ambient Library

Fork of AmbientLib by Takehiko Shimojima

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 clear (int field)
 Clear data on field-th field of payload.
bool send (void)
 Send 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 61 of file Ambient.h.


Constructor & Destructor Documentation

AMBIENT ( void   )

Create AMBIENT instance.

Definition at line 20 of file Ambient.cpp.


Member Function Documentation

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 error

Definition at line 68 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 error

Definition at line 24 of file Ambient.cpp.

bool send ( void   )

Send data to Ambient.

Definition at line 79 of file Ambient.cpp.

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 error