EnOcean Link  1.14.0.0
Middleware to Connect EnOcean easily to other Projects
Tutorial 3

In this Tutorial tutorial3.cpp we receive Information from an EEP A5-02-05 and translate it to A5-02-20 Profile. The same configuration as in Tutorial 2 is used and loaded.

eoGateway myGateway;
printf("Opening Connection to USB300 \n");
if (myGateway.Open(SER_PORT)!=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;

Now as we want to send data, we've to create an eoTelegram and eoProfile. To create an eoProfile we use the static function eoProfileFactory::CreateProfile, which takes as paramaters either an eoTelegram containing a Teach IN telegram, or the RORG,FUNC,TYPE. If eoLink Supports you profile it returns a new instance of the selected profile otherwise it returns a null pointer.

eoProfile *sendProfile = eoProfileFactory::CreateProfile(0xA5,0x02,0x20);

Using the eoProfile we can call the eoProfile::CreateTeachIN function to prepare a teachIN Telegram and send it via the eoGateway.

if(sendProfile!=NULL)
sendProfile->CreateTeachIN(myTel);
myGateway.Send(myTel);

As in the previous examples, the eoGateway::Receive functions runs in a while loop. As soon as we get temperature, we use the eoProfile::SetValue function and the eoProfile::Create to generate a 4BS datatelegram. Now we use the eoGateway::Send to send the 4bs telegram.

while (1)
{
recv = myGateway.Receive();
//Got a Profile
if (recv & RECV_PROFILE)
{
printf("Device %08lX\n", myGateway.device->ID);
eoProfile *profile = myGateway.device->GetProfile();
float f;
//with a Temperature
if (profile->GetValue( S_TEMP, f) ==OK)
{
printf(" %.2f \n", f);
if(sendProfile==NULL)
continue;
//Use the eoProfile to set the temperature value
if(sendProfile->SetValue(S_TEMP,f)==OK)
{
//and send a Temperature Telegram
if(sendProfile->Create(myMessage)==OK)
myGateway.Send(myMessage);
}
}
}
}