Events
Any Thing can generate and then send an event back to the platform, but those events must be declared as part of the Thing, Thing Template, Thing Shape, or Data Shape declaration. Consider the following declaration:

TW_MAKE_THING(thingName,TW_THING_TEMPLATE_GENERIC);
TW_PROPERTY("FaultStatus",TW_NO_DESCRIPTION, TW_BOOLEAN);
TW_PROPERTY("InletValve", TW_NO_DESCRIPTION, TW_BOOLEAN);
TW_PROPERTY("Pressure", TW_NO_DESCRIPTION, TW_NUMBER);

TW_EVENT("SteamSensorFault",
"Steam sensor event",
TW_MAKE_DATASHAPE(
"SteamSensorFault",
TW_DS_ENTRY("message",TW_NO_DESCRIPTION,TW_STRING)
)
);
The Thing declaration above registers an event and specifies its Data Shape so the platform knows what fields to expect in the message. TW_EVENT wraps the following C SDK API function:

int twExt_Api_RegisterEvent(enum entityTypeEnum entityType,
char * entityName, char * eventName, char * eventDescription,
twDataShape * parameters);
Later this event can be fired with the following macro:

TW_FIRE_EVENT(thingName, "SteamSensorFault",
TW_MAKE_IT(TW_MAKE_DATASHAPE(
"SteamSensorFault",
TW_DS_ENTRY("message",TW_NO_DESCRIPTION,TW_STRING)
), TW_IT_ROW(TW_MAKE_STRING(msg))
));
This macro wraps the following C SDK API call:

int twExt_Api_FireEvent(enum entityTypeEnum entityType,
char * entityName, char * eventName, twInfoTable * params,
int32_t timeout, char forceConnect);
Was this helpful?