MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / message_callback

Function message_callback

chirpstack/src/integration/mqtt.rs:399–443  ·  view source on GitHub ↗
(
    application_id: String,
    dev_eui: String,
    command: String,
    json: bool,
    p: Publish,
)

Source from the content-addressed store, hash-verified

397}
398
399async fn message_callback(
400 application_id: String,
401 dev_eui: String,
402 command: String,
403 json: bool,
404 p: Publish,
405) {
406 let topic = String::from_utf8_lossy(&p.topic);
407
408 info!(topic = %topic, qos = ?p.qos, "Command received for device");
409
410 let err = || -> Result<()> {
411 match command.as_ref() {
412 "down" => {
413 let cmd: integration::DownlinkCommand = match json {
414 true => serde_json::from_slice(&p.payload)?,
415 false => integration::DownlinkCommand::decode(&mut Cursor::new(&p.payload))?,
416 };
417 if dev_eui != cmd.dev_eui {
418 return Err(anyhow!(
419 "Payload dev_eui {} does not match topic dev_eui {}",
420 cmd.dev_eui,
421 dev_eui
422 ));
423 }
424 tokio::spawn(super::handle_down_command(application_id, cmd));
425 }
426 _ => {
427 return Err(anyhow!("Unknown command type"));
428 }
429 }
430
431 Ok(())
432 }()
433 .err();
434
435 if err.is_some() {
436 warn!(
437 topic = %topic,
438 qos = ?p.qos,
439 "Processing command error: {}",
440 err.as_ref().unwrap()
441 );
442 }
443}
444
445#[cfg(all(test, feature = "test-integration-mqtt"))]
446pub mod test {

Callers 1

newMethod · 0.70

Calls 3

handle_down_commandFunction · 0.85
as_refMethod · 0.80
decodeFunction · 0.50

Tested by

no test coverage detected