only sending first 8 digits of value



  • Hi all,

    I am working on a I Button reader (Key Holder for homestatus use). I have everything working but one detail...
    I have 2 seperat OneWire conections (will be 4 in future), each is connected to one reader. Getting the ID of each button works fine but on the first reader I get the ID (8 byte long) and random numbers attached to the end when I send it.
    On the second reader there is also a number attached but it stays the same.

    • is there a way to shorten the send value (V_VAR1) to valid digits?

    thanks in advance

    oh yes, this is the sketch I am using:

    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    #define MY_IS_RFM69HW
    #define MY_RFM69_FREQUENCY RF69_433MHZ
    
    #define MY_NODE_ID 102 
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <OneWire.h>
    
    // This is the pin with the 1-Wire bus on it
    OneWire ds_1(3);
    OneWire ds_2(4);
    OneWire ds_3(5);
    OneWire ds_4(6);
    
    
    
    
    // unique serial number read from the key
    byte addr_1[8];
    int addr_1_last;
    byte addr_2[8];
    int addr_2_last;
    
    
    // poll delay (I think 750ms is a magic number for iButton)
    int del = 750;
    
    #define CHILD_ID_1 1
    #define CHILD_ID_2 2
    #define CHILD_ID_3 3
    
    MyMessage ReadMsg_1(CHILD_ID_1, V_VAR1);
    MyMessage ReadMsg_2(CHILD_ID_2, V_VAR2);
    MyMessage ReadMsg_3(CHILD_ID_3, V_VAR3);
    
    void setup() {
      Serial.begin(115200);
    }
    
    void presentation()  {
      sendSketchInfo("iButton Reader", "1.0");
      present(CHILD_ID_1, S_CUSTOM);
      present(CHILD_ID_2, S_CUSTOM);
      present(CHILD_ID_3, S_CUSTOM);
    }
    
    void loop() {
    byte result;
    
      // search looks through all devices on the bus
       ds_1.reset_search();
         for( int i = 0; i < 8;  ++i )
      addr_1[i] = (char)0;
       ds_1.search(addr_1);
    //   Serial.println(ds_1.crc8(addr_1,7));
      if(ds_1.crc8(addr_1,7) == 0 && addr_1_last == 0) {
    
      send(ReadMsg_1.set(0)); 
    addr_1_last = 1;
    
      for( int i = 0; i < 8;  ++i )
      addr_1[i] = (char)0;
      }  
      else if (ds_1.crc8(addr_1,7) >> 0  && addr_1_last == 1){
    
        send(ReadMsg_1.set(addr_1,HEX)); 
         addr_1_last = 0;
    
      }
       ds_2.reset_search();
         for( int i = 0; i < 8;  ++i )
      addr_2[i] = (char)0;
       ds_2.search(addr_2);
     //  Serial.println(ds_2.crc8(addr_2,7));
      if(ds_2.crc8(addr_2,7) == 0 && addr_2_last == 0) {
    
      send(ReadMsg_2.set(0)); 
    addr_2_last = 1;
    
      for( int i = 0; i < 8;  ++i )
      addr_2[i] = (char)0;
      }  
      else if (ds_2.crc8(addr_2,7) >> 0  && addr_2_last == 1){
        
    
        send(ReadMsg_2.set(addr_2,HEX)); 
         addr_2_last = 0;
    
      }
    
      delay(del);
      return;
      }
    
    

    edit:
    for clarification:
    this is the 8 byte code:
    "0102E47F1600003F"
    but V_VARxxx is something like:
    "0102E47F1600003F0000017CD2861800"
    so first 16 digits are correct then random 😞


Log in to reply
 

Suggested Topics

  • 3
  • 3
  • 24
  • 15
  • 2
  • 2

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts