void TemperatureSensor::onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
int eCode, int sequenceNumber)
{
- if (eCode == OC_STACK_OK)
+ if (eCode == OC_STACK_OK && sequenceNumber != OC_OBSERVE_NO_OPTION)
{
+ if(sequenceNumber == OC_OBSERVE_REGISTER)
+ {
+ cout << "Observe registration action is successful" << endl;
+ }
+ else if(sequenceNumber == OC_OBSERVE_DEREGISTER)
+ {
+ cout << "Observe De-registration action is successful" << endl;
+ }
double value;
rep.getValue(TEMPERATURE_RESOURCE_KEY, value);
cout << "Observing TemperatureSensor: Current temperature reading in Celsius is " << value << endl;
}
else
{
- cerr << "TemperatureSensor: Observer response error" << endl;
+ if(sequenceNumber == OC_OBSERVE_NO_OPTION)
+ {
+ cerr << "Observe registration or de-registration action is failed" << endl;
+ }
+ else
+ {
+ cerr << "TemperatureSensor: Observer response error" << endl;
+ }
}
}
{
try
{
- if(eCode == OC_STACK_OK)
+ if(eCode == OC_STACK_OK && sequenceNumber != OC_OBSERVE_NO_OPTION)
{
+ if(sequenceNumber == OC_OBSERVE_REGISTER)
+ {
+ std::cout << "Observe registration action is successful" << std::endl;
+ }
+ else if(sequenceNumber == OC_OBSERVE_DEREGISTER)
+ {
+ std::cout << "Observe De-registration action is successful" << std::endl;
+ }
+
std::cout << "OBSERVE RESULT:"<<std::endl;
std::cout << "\tSequenceNumber: "<< sequenceNumber << std::endl;
rep.getValue("state", mylight.m_state);
}
else
{
- std::cout << "onObserve Response error: " << eCode << std::endl;
- std::exit(-1);
+ if(sequenceNumber == OC_OBSERVE_NO_OPTION)
+ {
+ std::cout << "Observe registration or de-registration action is failed" << std::endl;
+ }
+ else
+ {
+ std::cout << "onObserve Response error: " << eCode << std::endl;
+ std::exit(-1);
+ }
}
}
catch(std::exception& e)