コード例 #1
0
ファイル: door_trip.cpp プロジェクト: awatt196/resources
//This is to be called from main program loop... it only sends report if door tripped.
void door_trip_report() {
    if(obs_number != 0){
        obs_number++;
        snprintf(door_trip_val,2,"%d" ,current_door_trip_value);
        if(sn_nsdl_send_observation_notification(obs_token_ptr, obs_token_len, (uint8_t*)door_trip_val, 1, &obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0) {
            pc.printf("Door Trip Observation Sending Failed\r\n");
        } else {
            pc.printf("Door Trip Observation Sent\r\n");
        }
    }
} 
コード例 #2
0
/*
Thread to sample the input and use the update callback on_update when sensor values change.
on_update will run the limits test and set the notification event trigger accordingly.
Also checks for the event trigger and sends a notification packet in this thread.
This allows the notification trigger to be set in a hardware timer ISR without blocking
the ISR with a network operation.
*/
static void LWM2M_notification_thread(void const *args)
{
    while (true){
        wait(.1);
        current_sample = LWM2M_Sensor.read() * (float) 100;
        
        // if this csample is different from last sample, then call the resource on_update
        if((current_sample != last_sample) && LWM2M_observing){
            //pc.printf("LWM2M resource update: %3.1f => %3.1f\r\n", last_sample, current_sample);
            last_sample = current_sample;
            on_update(current_sample); // callback to process notification attributes
        }
        
        // if triggered and in observing mode, build and send the notification packet
        if (notification_trigger && LWM2M_observing){
            
            if (pmax_exceeded){ pc.printf("pmax exceeded\r\n"); pmax_exceeded = false; }
            if (pmin_trigger){pc.printf("pmin trigger\r\n"); pmin_trigger = false; }
            
            sprintf(LWM2M_value_string, "%3.1f", notify_sample); 
            pc.printf("Sending: %s\r\n", LWM2M_value_string);        
            LWM2M_obs_number++;
            if(sn_nsdl_send_observation_notification
                (LWM2M_obs_token_ptr, LWM2M_obs_token_len, 
                (uint8_t*)LWM2M_value_string, strlen(LWM2M_value_string), 
                &LWM2M_obs_number, sizeof(LWM2M_obs_number), 
                COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0){
                    
                pc.printf("LWM2M notification failed\r\n");
            }
            else{
                pc.printf("LWM2M notification\r\n");
                notification_trigger = false;
            }
        }
    }
}