fn send_sensor_data(val: &SensorValue) -> MynewtResult<()> {
        console::print("Rust send_sensor_data: ");
        if let SensorValueType::Uint(i) = val.value {
            console::print_strn(val.key);
            console::print("=");
            console::printint(i as i32);
        }
        console::print("\n");
        console::flush();
        let device_id = sensor_network::get_device_id()?;
        let rc = sensor_network::init_server_post(&Strn::new(b"\0"))?;
        if !rc { return Err(MynewtError::SYS_EAGAIN); }
        let _payload =
            {
                "begin json root";
                {
                    "begin json coap_root";
                    unsafe {
                        mynewt::libs::sensor_network::prepare_post(mynewt::encoding::APPLICATION_JSON)?;
                    }
                    unsafe {
                        mynewt::libs::sensor_coap::json_rep_start_root_object();
                    }
                    {
                        {
                            "begin json coap_array, object : COAP_CONTEXT, key : values";
                            {
                                "<< jarri , o: COAP_CONTEXT, k: values";
                                let key_with_null: &str = "values\u{0}";
                                unsafe {
                                    mynewt::libs::mynewt_rust::json_helper_set_array(COAP_CONTEXT.to_void_ptr(),
                                                                                     COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()));
                                };
                            };
                            {
                                " >>  >> val >> , \"device\" : & device_id,";
                                "--------------------";
                                {
                                    "begin json coap_item_int_val, c : COAP_CONTEXT, val : val";
                                    let geo = val.geo;
                                    if let SensorValueType::Uint(val) =
                                           val.value {
                                        {
                                            "begin json coap_item_int, key : val.key, value : val";
                                            {
                                                "begin json coap_item, array : COAP_CONTEXT";
                                                {
                                                    "<< jitmi c: COAP_CONTEXT";
                                                    let key_with_null: &str =
                                                        "COAP_CONTEXT\u{0}";
                                                    unsafe {
                                                        mynewt::libs::mynewt_rust::json_helper_object_array_start_item(COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                                    };
                                                };
                                                {
                                                    {
                                                        "-- jtxte o: COAP_CONTEXT, k: \"key\", v: val.key";
                                                        let key_with_opt_null:
                                                                &[u8] =
                                                            "key".to_bytes_optional_nul();
                                                        let value_with_opt_null:
                                                                &[u8] =
                                                            val.key.to_bytes_optional_nul();
                                                        unsafe {
                                                            mynewt::libs::mynewt_rust::json_helper_set_text_string(COAP_CONTEXT.to_void_ptr(),
                                                                                                                   COAP_CONTEXT.key_to_cstr(key_with_opt_null),
                                                                                                                   COAP_CONTEXT.value_to_cstr(value_with_opt_null))
                                                        };
                                                    };
                                                    {
                                                        "-- jinte o: COAP_CONTEXT, k: \"value\", v: val";
                                                        let key_with_opt_null:
                                                                &[u8] =
                                                            "value".to_bytes_optional_nul();
                                                        let value =
                                                            val as u64;
                                                        unsafe {
                                                            mynewt::libs::mynewt_rust::json_helper_set_int(COAP_CONTEXT.to_void_ptr(),
                                                                                                           COAP_CONTEXT.key_to_cstr(key_with_opt_null),
                                                                                                           value)
                                                        };
                                                    };
                                                    unsafe {
                                                        COAP_CONTEXT.json_set_geolocation(&Strn::new(b"geo\x00"),
                                                                                          &Strn::new(b"lat\x00"),
                                                                                          &Strn::new(b"long\x00"),
                                                                                          geo)
                                                    };
                                                };
                                                {
                                                    ">>";
                                                    let key_with_null: &str =
                                                        "COAP_CONTEXT\u{0}";
                                                    unsafe {
                                                        mynewt::libs::mynewt_rust::json_helper_object_array_end_item(COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                                    };
                                                };
                                                "end json coap_item";
                                            };
                                            "end json coap_item_int";
                                        };
                                    } else {
                                        unsafe {
                                            COAP_CONTEXT.fail(CoapError::VALUE_NOT_UINT)
                                        };
                                    }
                                    "end json coap_item_int_val";
                                };
                                "--------------------";
                                " >>  >> \"device\" >> : & device_id,";
                                "add1 key : \"device\" value : ::mynewt::parse!(@ json &device_id) to object :\nCOAP_CONTEXT";
                                {
                                    "begin json coap_item_str, parent : COAP_CONTEXT, key : \"device\", val :\n::mynewt::parse!(@ json &device_id)";
                                    {
                                        "begin json coap_item, array : COAP_CONTEXT";
                                        {
                                            "<< jitmi c: COAP_CONTEXT";
                                            let key_with_null: &str =
                                                "COAP_CONTEXT\u{0}";
                                            unsafe {
                                                mynewt::libs::mynewt_rust::json_helper_object_array_start_item(COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                            };
                                        };
                                        {
                                            {
                                                "-- jtxti o: COAP_CONTEXT, k: key, v: \"device\"";
                                                let key_strn: &Strn =
                                                    &Strn::new(b"key\x00");
                                                let value_strn: &Strn =
                                                    &Strn::new(b"device\x00");
                                                unsafe {
                                                    COAP_CONTEXT.json_set_text_string(key_strn,
                                                                                      value_strn)
                                                };
                                            };
                                            {
                                                "-- jtxti o: COAP_CONTEXT, k: value, v: ::mynewt::parse!(@ json &device_id)";
                                                let key_strn: &Strn =
                                                    &Strn::new(b"value\x00");
                                                let value_strn: &Strn =
                                                    &device_id;
                                                unsafe {
                                                    COAP_CONTEXT.json_set_text_string(key_strn,
                                                                                      value_strn)
                                                };
                                            };
                                        };
                                        {
                                            ">>";
                                            let key_with_null: &str =
                                                "COAP_CONTEXT\u{0}";
                                            unsafe {
                                                mynewt::libs::mynewt_rust::json_helper_object_array_end_item(COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                            };
                                        };
                                        "end json coap_item";
                                    };
                                    "end json coap_item_str";
                                };
                                "--------------------";
                            };
                            {
                                ">>";
                                let key_with_null: &str = "values\u{0}";
                                unsafe {
                                    mynewt::libs::mynewt_rust::json_helper_close_array(COAP_CONTEXT.to_void_ptr(),
                                                                                       COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                };
                            };
                            "end json coap_array";
                        };
                    };
                    unsafe {
                        mynewt::libs::sensor_coap::json_rep_end_root_object();
                    }
                    "end json coap_root";
                };
                "end json root";
                ()
            };
        sensor_network::do_server_post()?;
        console::print("NET view your sensor at \nhttps://blue-pill-geolocate.appspot.com?device=");
        console::print_strn(&device_id);
        console::print("\n");
        Ok(())
    }
/// Compose a CoAP JSON message with the Sensor Key (field name), Value and Geolocation (optional) in `val`
/// and send to the CoAP server.  The message will be enqueued for transmission by the CoAP / OIC 
/// Background Task so this function will return without waiting for the message to be transmitted.
/// Return `Ok()` if successful, `SYS_EAGAIN` if network is not ready yet.
/// For the CoAP server hosted at thethings.io, the CoAP payload shall be encoded in JSON like this:
/// ```json
/// {"values":[
///   {"key":"t",      "value":1715, "geo": { "lat": ..., "long": ... }},
///   {"key":"device", "value":"0102030405060708090a0b0c0d0e0f10"}
/// ]}
/// ```
Compose a CoAP JSON message with the Sensor Key (field name), Value and Geolocation (optional) in `val`
and send to the CoAP server.  The message will be enqueued for transmission by the CoAP / OIC
Background Task so this function will return without waiting for the message to be transmitted.
Return `Ok()` if successful, `SYS_EAGAIN` if network is not ready yet.
Compose a CoAP JSON message with the Sensor Key ( field name ) Value and Geolocation ( optional ) in ` val ` and send to the CoAP server . The message will be enqueued for transmission by the CoAP / OIC Background Task so this function will return without waiting for the message to be transmitted . Return ` Ok () ` if successful ` SYS_EAGAIN ` if network is not ready yet .
fn send_sensor_data(val: &SensorValue) -> MynewtResult<()> {
        console::print("Rust send_sensor_data: ");
        if let SensorValueType::Uint(i) = val.value {
            console::print_strn(val.key);
            console::print("=");
            console::printint(i as i32);
        }
        console::print("\n");
        console::flush();
        let device_id = sensor_network::get_device_id()?;
        let rc = sensor_network::init_server_post(&Strn::new(b"\0"))?;
        if !rc { return Err(MynewtError::SYS_EAGAIN); }
        let _payload =
            {
                "begin json root";
                {
                    "begin json coap_root";
                    unsafe {
                        mynewt::libs::sensor_network::prepare_post(mynewt::encoding::APPLICATION_JSON)?;
                    }
                    unsafe {
                        mynewt::libs::sensor_coap::json_rep_start_root_object();
                    }
                    {
                        {
                            "begin json coap_array, object : COAP_CONTEXT, key : values";
                            {
                                "<< jarri , o: COAP_CONTEXT, k: values";
                                let key_with_null: &str = "values\u{0}";
                                unsafe {
                                    mynewt::libs::mynewt_rust::json_helper_set_array(COAP_CONTEXT.to_void_ptr(),
                                                                                     COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()));
                                };
                            };
                            {
                                " >>  >> val >> , \"device\" : & device_id,";
                                "--------------------";
                                {
                                    "begin json coap_item_int_val, c : COAP_CONTEXT, val : val";
                                    let geo = val.geo;
                                    if let SensorValueType::Uint(val) =
                                           val.value {
                                        {
                                            "begin json coap_item_int, key : val.key, value : val";
                                            {
                                                "begin json coap_item, array : COAP_CONTEXT";
                                                {
                                                    "<< jitmi c: COAP_CONTEXT";
                                                    let key_with_null: &str =
                                                        "COAP_CONTEXT\u{0}";
                                                    unsafe {
                                                        mynewt::libs::mynewt_rust::json_helper_object_array_start_item(COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                                    };
                                                };
                                                {
                                                    {
                                                        "-- jtxte o: COAP_CONTEXT, k: \"key\", v: val.key";
                                                        let key_with_opt_null:
                                                                &[u8] =
                                                            "key".to_bytes_optional_nul();
                                                        let value_with_opt_null:
                                                                &[u8] =
                                                            val.key.to_bytes_optional_nul();
                                                        unsafe {
                                                            mynewt::libs::mynewt_rust::json_helper_set_text_string(COAP_CONTEXT.to_void_ptr(),
                                                                                                                   COAP_CONTEXT.key_to_cstr(key_with_opt_null),
                                                                                                                   COAP_CONTEXT.value_to_cstr(value_with_opt_null))
                                                        };
                                                    };
                                                    {
                                                        "-- jinte o: COAP_CONTEXT, k: \"value\", v: val";
                                                        let key_with_opt_null:
                                                                &[u8] =
                                                            "value".to_bytes_optional_nul();
                                                        let value =
                                                            val as u64;
                                                        unsafe {
                                                            mynewt::libs::mynewt_rust::json_helper_set_int(COAP_CONTEXT.to_void_ptr(),
                                                                                                           COAP_CONTEXT.key_to_cstr(key_with_opt_null),
                                                                                                           value)
                                                        };
                                                    };
                                                    unsafe {
                                                        COAP_CONTEXT.json_set_geolocation(&Strn::new(b"geo\x00"),
                                                                                          &Strn::new(b"lat\x00"),
                                                                                          &Strn::new(b"long\x00"),
                                                                                          geo)
                                                    };
                                                };
                                                {
                                                    ">>";
                                                    let key_with_null: &str =
                                                        "COAP_CONTEXT\u{0}";
                                                    unsafe {
                                                        mynewt::libs::mynewt_rust::json_helper_object_array_end_item(COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                                    };
                                                };
                                                "end json coap_item";
                                            };
                                            "end json coap_item_int";
                                        };
                                    } else {
                                        unsafe {
                                            COAP_CONTEXT.fail(CoapError::VALUE_NOT_UINT)
                                        };
                                    }
                                    "end json coap_item_int_val";
                                };
                                "--------------------";
                                " >>  >> \"device\" >> : & device_id,";
                                "add1 key : \"device\" value : ::mynewt::parse!(@ json &device_id) to object :\nCOAP_CONTEXT";
                                {
                                    "begin json coap_item_str, parent : COAP_CONTEXT, key : \"device\", val :\n::mynewt::parse!(@ json &device_id)";
                                    {
                                        "begin json coap_item, array : COAP_CONTEXT";
                                        {
                                            "<< jitmi c: COAP_CONTEXT";
                                            let key_with_null: &str =
                                                "COAP_CONTEXT\u{0}";
                                            unsafe {
                                                mynewt::libs::mynewt_rust::json_helper_object_array_start_item(COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                            };
                                        };
                                        {
                                            {
                                                "-- jtxti o: COAP_CONTEXT, k: key, v: \"device\"";
                                                let key_strn: &Strn =
                                                    &Strn::new(b"key\x00");
                                                let value_strn: &Strn =
                                                    &Strn::new(b"device\x00");
                                                unsafe {
                                                    COAP_CONTEXT.json_set_text_string(key_strn,
                                                                                      value_strn)
                                                };
                                            };
                                            {
                                                "-- jtxti o: COAP_CONTEXT, k: value, v: ::mynewt::parse!(@ json &device_id)";
                                                let key_strn: &Strn =
                                                    &Strn::new(b"value\x00");
                                                let value_strn: &Strn =
                                                    &device_id;
                                                unsafe {
                                                    COAP_CONTEXT.json_set_text_string(key_strn,
                                                                                      value_strn)
                                                };
                                            };
                                        };
                                        {
                                            ">>";
                                            let key_with_null: &str =
                                                "COAP_CONTEXT\u{0}";
                                            unsafe {
                                                mynewt::libs::mynewt_rust::json_helper_object_array_end_item(COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                            };
                                        };
                                        "end json coap_item";
                                    };
                                    "end json coap_item_str";
                                };
                                "--------------------";
                            };
                            {
                                ">>";
                                let key_with_null: &str = "values\u{0}";
                                unsafe {
                                    mynewt::libs::mynewt_rust::json_helper_close_array(COAP_CONTEXT.to_void_ptr(),
                                                                                       COAP_CONTEXT.key_to_cstr(key_with_null.as_bytes()))
                                };
                            };
                            "end json coap_array";
                        };
                    };
                    unsafe {
                        mynewt::libs::sensor_coap::json_rep_end_root_object();
                    }
                    "end json coap_root";
                };
                "end json root";
                ()
            };
        sensor_network::do_server_post()?;
        console::print("NET view your sensor at \nhttps://blue-pill-geolocate.appspot.com?device=");
        console::print_strn(&device_id);
        console::print("\n");
        Ok(())
    }
fn send_sensor_data ( val : & SensorValue ) -> MynewtResult < ( ) > { console :: print ( " " ) ; if let SensorValueType :: Uint ( i ) = val . value { console :: print_strn ( val . key ) ; console :: print ( " " ) ; console :: printint ( i as i32 ) ; } console :: print ( " \n " ) ; console :: flush ( ) ; let device_id = sensor_network :: get_device_id ( ) ? ; let rc = sensor_network :: init_server_post ( & Strn :: new ( b" \0 " ) ) ? ; if ! rc { return Err ( MynewtError :: SYS_EAGAIN ) ; } let _payload = { " " ; { " " ; unsafe { mynewt :: libs :: sensor_network :: prepare_post ( mynewt :: encoding :: APPLICATION_JSON ) ? ; } unsafe { mynewt :: libs :: sensor_coap :: json_rep_start_root_object ( ) ; } { { " " ; { " " ; let key_with_null : & str = " \u{0} " ; unsafe { mynewt :: libs :: mynewt_rust :: json_helper_set_array ( COAP_CONTEXT . to_void_ptr ( ) , COAP_CONTEXT . key_to_cstr ( key_with_null . as_bytes ( ) ) ) ; } ; } ; { " \" \" " ; " " ; { " " ; let geo = val . geo ; if let SensorValueType :: Uint ( val ) = val . value { { " " ; { " " ; { " " ; let key_with_null : & str = " \u{0} " ; unsafe { mynewt :: libs :: mynewt_rust :: json_helper_object_array_start_item ( COAP_CONTEXT . key_to_cstr ( key_with_null . as_bytes ( ) ) ) } ; } ; { { " \" \" " ; let key_with_opt_null : & [ u8 ] = " " . to_bytes_optional_nul ( ) ; let value_with_opt_null : & [ u8 ] = val . key . to_bytes_optional_nul ( ) ; unsafe { mynewt :: libs :: mynewt_rust :: json_helper_set_text_string ( COAP_CONTEXT . to_void_ptr ( ) , COAP_CONTEXT . key_to_cstr ( key_with_opt_null ) , COAP_CONTEXT . value_to_cstr ( value_with_opt_null ) ) } ; } ; { " \" \" " ; let key_with_opt_null : & [ u8 ] = " " . to_bytes_optional_nul ( ) ; let value = val as u64 ; unsafe { mynewt :: libs :: mynewt_rust :: json_helper_set_int ( COAP_CONTEXT . to_void_ptr ( ) , COAP_CONTEXT . key_to_cstr ( key_with_opt_null ) , value ) } ; } ; unsafe { COAP_CONTEXT . json_set_geolocation ( & Strn :: new ( b" \x00 " ) , & Strn :: new ( b" \x00 " ) , & Strn :: new ( b" \x00 " ) , geo ) } ; } ; { " " ; let key_with_null : & str = " \u{0} " ; unsafe { mynewt :: libs :: mynewt_rust :: json_helper_object_array_end_item ( COAP_CONTEXT . key_to_cstr ( key_with_null . as_bytes ( ) ) ) } ; } ; " " ; } ; " " ; } ; } else { unsafe { COAP_CONTEXT . fail ( CoapError :: VALUE_NOT_UINT ) } ; } " " ; } ; " " ; " \" \" " ; " \" \" \n " ; { " \" \" \n " ; { " " ; { " " ; let key_with_null : & str = " \u{0} " ; unsafe { mynewt :: libs :: mynewt_rust :: json_helper_object_array_start_item ( COAP_CONTEXT . key_to_cstr ( key_with_null . as_bytes ( ) ) ) } ; } ; { { " \" \" " ; let key_strn : & Strn = & Strn :: new ( b" \x00 " ) ; let value_strn : & Strn = & Strn :: new ( b" \x00 " ) ; unsafe { COAP_CONTEXT . json_set_text_string ( key_strn , value_strn ) } ; } ; { " " ; let key_strn : & Strn = & Strn :: new ( b" \x00 " ) ; let value_strn : & Strn = & device_id ; unsafe { COAP_CONTEXT . json_set_text_string ( key_strn , value_strn ) } ; } ; } ; { " " ; let key_with_null : & str = " \u{0} " ; unsafe { mynewt :: libs :: mynewt_rust :: json_helper_object_array_end_item ( COAP_CONTEXT . key_to_cstr ( key_with_null . as_bytes ( ) ) ) } ; } ; " " ; } ; " " ; } ; " " ; } ; { " " ; let key_with_null : & str = " \u{0} " ; unsafe { mynewt :: libs :: mynewt_rust :: json_helper_close_array ( COAP_CONTEXT . to_void_ptr ( ) , COAP_CONTEXT . key_to_cstr ( key_with_null . as_bytes ( ) ) ) } ; } ; " " ; } ; } ; unsafe { mynewt :: libs :: sensor_coap :: json_rep_end_root_object ( ) ; } " " ; } ; " " ; ( ) } ; sensor_network :: do_server_post ( ) ? ; console :: print ( " \n " ) ; console :: print_strn ( & device_id ) ; console :: print ( " \n " ) ; Ok ( ( ) ) }
Compose a CoAP JSON message with the Sensor Key (field name), Value and Geolocation (optional) in `val`
and send to the CoAP server.
Compose a CoAP JSON message with the Sensor Key ( field name ) Value and Geolocation ( optional ) in ` val ` and send to the CoAP server .
val
&SensorValue
val
&SensorValue