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.2k 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.
  • EasyIoTE Offline
    EasyIoTE 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
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      Yes, you're right!

      I will change this.

      1 Reply Last reply
      0
      • EasyIoTE Offline
        EasyIoTE 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
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        17

        Online

        11.7k

        Users

        11.2k

        Topics

        113.1k

        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