Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Bug Reports
  3. Sensor::readMessage()

Sensor::readMessage()

Scheduled Pinned Locked Moved Bug Reports
3 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EasyIoT
    wrote on last edited by
    #1

    When I ported sensor.cpp to C# i notice:

    boolean Sensor::readMessage() {
    uint8_t len = RF24::getDynamicPayloadSize();
    RF24::read(&msg, len);

    if (!(msg.header.messageType==M_INTERNAL && msg.header.type == I_PING_ACK)) {
    	delay(ACK_SEND_DELAY); // Small delay here to let other side switch to reading mode
    	RF24::stopListening();
    	RF24::openWritingPipe(TO_ADDR(msg.header.last));
    	RF24::write(&radioId, sizeof(uint8_t));
    	RF24::closeReadingPipe(WRITE_PIPE); // Stop listening to write-pipe after transmit
    	RF24::startListening();
    	debug(PSTR("Sent ack msg to %d\n"), msg.header.last);
    }
    uint8_t valid = validate(len-sizeof(header_s));
    boolean ok = valid == VALIDATE_OK;
    
    // Make sure string gets terminated ok for full sized messages.
    msg.data[len - sizeof(header_s) ] = '\0';
    debug(PSTR("Rx: fr=%d,to=%d,la=%d,ci=%d,mt=%d,t=%d,cr=%d(%s): %s\n"),
    		msg.header.from,msg.header.to, msg.header.last, msg.header.childId, msg.header.messageType, msg.header.type, msg.header.crc, valid==0?"ok":valid==1?"ec":"ev", msg.data);
    return ok;
    

    }

    Is this correct? Isn't better to first validante message and then send confirmation if it is ok. Like this:

    boolean Sensor::readMessage() {
    uint8_t len = RF24::getDynamicPayloadSize();
    RF24::read(&msg, len);

    uint8_t valid = validate(len-sizeof(header_s));
    boolean ok = valid == VALIDATE_OK;**
    **
    if (ok && !(msg.header.messageType==M_INTERNAL && msg.header.type == I_PING_ACK)) {
    delay(ACK_SEND_DELAY); // Small delay here to let other side switch to reading mode
    RF24::stopListening();
    RF24::openWritingPipe(TO_ADDR(msg.header.last));
    RF24::write(&radioId, sizeof(uint8_t));
    RF24::closeReadingPipe(WRITE_PIPE); // Stop listening to write-pipe after transmit
    RF24::startListening();
    debug(PSTR("Sent ack msg to %d\n"), msg.header.last);
    }

    // Make sure string gets terminated ok for full sized messages.
    msg.data[len - sizeof(header_s) ] = '\0';
    debug(PSTR("Rx: fr=%d,to=%d,la=%d,ci=%d,mt=%d,t=%d,cr=%d(%s): %s\n"),
    		msg.header.from,msg.header.to, msg.header.last, msg.header.childId, msg.header.messageType, msg.header.type, msg.header.crc, valid==0?"ok":valid==1?"ec":"ev", msg.data);
    return ok;
    

    }

    --
    EasyIoT framework http://iot-playground.com

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hek
      Admin
      wrote on last edited by
      #2

      Yes, you're right!

      I will change this.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EasyIoT
        wrote on last edited by
        #3

        Also in RelayActuator.ino

        void setRelayStatus(message_s message) {
        if (message.header.messageType=M_SET_VARIABLE &&
        message.header.type==V_LIGHT) {

        is better:

        void setRelayStatus(message_s message) {
        if ((message.header.messageType==M_SET_VARIABLE || message.header.messageType==M_ACK_VARIABLE ) &&
        message.header.type==V_LIGHT) {

        Be careful message.header.messageType=M_SET_VARIABLE and message.header.messageType==M_SET_VARIABLE is not the same.

        --
        EasyIoT framework http://iot-playground.com

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        14

        Online

        12.0k

        Users

        11.2k

        Topics

        113.4k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular