Sending an integer >32767



  • Hey there,

    I'm trying to send a value between 10.000 and 99.999, but as soon as it gets bigger than 32.767 (size of int16) I receive totally senseless numbers. Is there a way to send this big number e.g. with an int32? I use V_VAR1 as message type.

    Regards,
    Anduril



  • @Anduril
    I have checked my sketches. But I don't know so much about code.

    double VAR1
    long VAR1

    Try if they work


  • Hero Member

    @Anduril Are you sending it from your sketch or the controller? If you are sending from the sketch make sure the "setter"

       // Setters for payload
        MyMessage& set(void* payload, uint8_t length);
        MyMessage& set(const char* value);
        MyMessage& set(uint8_t value);
        MyMessage& set(float value, uint8_t decimals);
        MyMessage& set(unsigned long value);
        MyMessage& set(long value);
        MyMessage& set(unsigned int value);
        MyMessage& set(int value);
    
    

    can recognize the variable as a type > int16. (long or unsigned long) i.e
    unsigned long variableToBeSend = 1234567 UL ;

    I assume the value is now 'overflowing' to a negative number.



  • I tried to send from controller. When sending 32768 the node 'received' 4294934528 (written to the serial monitor)...



  • well I did some further testing... sending e.g. 65000 from the node to the controller works, sending back 65001 does not. That seems more related to the controller (MyController) than MySensors. Maybe @jkandasa can help shine some light on this.



  • I found the problem... or to be honest @jkandasa found it. He told me in the MyController forum to check my receiving code and not use getInt() but getLong(). Thanks again to him.


  • Mod

    @Anduril great that you found the problem. Thanks for sharing the solution, it might help someone else in the future.


 

314
Online

8.0k
Users

8.8k
Topics

94.3k
Posts