EnOcean Link  1.14.0.0
Middleware to Connect EnOcean easily to other Projects
tutorial3.cpp
#ifdef WIN32
#define SER_PORT "\\\\.\\COM3" //COM43
#else
#define SER_PORT "/dev/ttyUSB0"
#endif
#define LOAD_CONFIG "./Tutorial2.txt"
#include "./eoLink.h"
#include <stdio.h>
int main(int argc, const char* argv[])
{
(void)argc;
(void)argv;
eoGateway myGateway;
printf("Opening Connection to USB300 \n");
if (myGateway.Open(SER_PORT)!=EO_OK)
{
printf("Failed to open USB300\n");
return 0;
}
//Loading the prepared Configuartion
myStore.addObject("Gateway",&myGateway);
myStore.Load(LOAD_CONFIG);
printf("Loaded Config \n");
uint16_t recv;
//As we send a 4BS Telegram, we need 4 data bytes
eoMessage myMessage = eoMessage(4);
//Creates a profile to create 4BS telegrams.
eoProfile *sendProfile = eoProfileFactory::CreateProfile(0xA5,0x02,0x20);
if(sendProfile!=NULL)
{
sendProfile->CreateTeachIN(myMessage);
}
myGateway.Send(myMessage);
while (1)
{
recv = myGateway.Receive();
//Got a Profile
if (recv & RECV_PROFILE)
{
printf("Device %08X\n", myGateway.device->ID);
eoProfile *profile = myGateway.device->GetProfile();
float f;
//with a Temperature
if (profile->GetValue( S_TEMP, f) ==EO_OK)
{
printf(" %.2f \n", f);
if(sendProfile==NULL)
{
continue;
}
//Use the eoProfile to set the temperature value
if(sendProfile->SetValue(S_TEMP,f)==EO_OK)
{
//and send a Temperature Telegram
if(sendProfile->Create(myMessage)==EO_OK)
{
myGateway.Send(myMessage);
}
}
}
}
}
return 0;
}