ThingWorx Edge SDK Extensions for the C SDK > Advanced Use of Edge Extensions > Modifying Property Values at Runtime
  
Modifying Property Values at Runtime
Once you have declared properties, you can set values on them, using the TW_SET_PROPERTY macro:
TW_SET_PROPERTY(thingName, propertyName,value)
where:
thingName—The name of the Edge Thing (a String) that was used to declare the thing.
propertyName—The name of the property for which you want to change the value.
value—The new value for the property.
This macro sets the specified value on the named property. You can this macro at any time. Unlike the TW_PROPERTY macro, the TW_SET_PROPERTY macro does not require a context. The thingName parameter is a string name for the thing.
The new C API function that supports the TW_SET_PROPERTY macro follows:

void twExt__SetPropertyValue(char *thingname, char *propertyName, twPrimitive *value);
Macros to Retrieve Property Values
The TW_GET_PROPERTY(thingName, propertyName) macro returns the requested property value as a twPrimitive. In general, you can use primitives to pass arguments to other macros. However, to get an actual C primitive type, you must use the C member access operator (.). The returned twPrimitive is actually a variant structure as shown below:

typedef struct twPrimitive {
enum BaseType type;
enum BaseType typeFamily;
uint32_t length;
union {
int32_t integer;
double number;
DATETIME datetime;
twLocation location;
char boolean;
struct {
char * data; /**< Value data pointer. **/
int32_t len; /**< Value data length. **/
} bytes;
struct twInfoTable * infotable;
struct twPrimitive * variant;
} val; /**< The value of the primitive. **/
} twPrimitive;
To access the double value of a TW_NUMBER property, you would call:
TW_GET_PROPERTY(Temperature).number
The result would be a C double.
Additional macros for retrieving values of properties include the following:
TW_GET_STRING_PROPERTY(thingName, propertyName)—Identical to TW_GET_PROPERTY except that it returns the .bytes.data field, which can be treated as a C char * or string.
TW_GET_PROPERTY_TYPE(thingName, propertyName)—Similar to TW_GET_PROPERTY except that it returns the primitive type of a property as a C int, as discussed in Macros to Create twPrimitives from C Primitives.
TW_PUSH_PROPERTIES_FOR(thingName)—Causes all property changes created with TW_SET_PROPERTY to be delivered to the platform. The thingName argument is the registered thing name for which you intend to push properties.
The following example shows how to update and read back a property value:

TW_SET_PROPERTY(thingName, "TotalFlow", TW_MAKE_NUMBER(rand() / (RAND_MAX / 10.0)));
TW_SET_PROPERTY(thingName, "Pressure", TW_MAKE_NUMBER(18 + rand() / (RAND_MAX / 5.0)));

double temp = TW_GET_PROPERTY(thingName, "Temperature").number;

char* serialNumber = TW_GET_STRING_PROPERTY(thingName, "serialNumber");
The new C API function that supports the GET macros is:

twPrimitive* twExt_GetPropertyValue(char *thingname, char *propertyName);
Tips
Keep in mind that calling TW_SET_PROPERY() does not actually deliver data to the server. It only records the change in memory for later delivery when the TW_PUSH_PROPERTIES_FOR() command is called.
It is important to keep in mind that TW_(GET/SET)_PROPERTY() both use the heap-based, hashed storage system, which is compatible with the twExt_GenericPropertyHandler() discussed in Declaring Edge Things. They do not work with any other custom cb_property handler.