Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Generating *raw data* string for BadgeMessage.
- #### Example of BadgeMessage:
- ``` json
- <Elpas><DeviceId>00:25:55:00:44:B8</DeviceId>
- <Type>BadgeMessage</Type><RawData>BFF874D565612E</RawData>
- <Id>03F874</Id><Motion>1</Motion><Battery>1</Battery>
- <RSSI>213</RSSI><Noise>101</Noise><Buttons>2</Buttons>
- <PacketId>2997</PacketId><Group>61</Group><Data>2E</Data></Elpas>
- ```
- #### Explanation of the first 2 byte forming added as a comment below.
- >**badge** - badge hex Neuron ID as string
- >
- >**motion** - *1* if in motion. *0* if motionless.
- >
- >**battery** - *1* if battery is OK. *0* if battery is low.
- >
- >**rssi** - integer value in 0-255 range
- >
- >**noise** - integer value in 0-255 range
- >
- >**data** - hex value as string
- >
- >**group** - hex value as string
- >
- >**button1** - *1* if button is pressed. *0* if button is released.
- >
- >**button2** - *1* if button is pressed. *0* if button is released.
- >
- >**message_type** - *11* if event message, *00* if supervision message
- >
- ##### According to our example:
- >**badge** - 03F874
- >
- >**motion** - *1*
- >
- >**battery** - *1*
- >
- >**rssi** - *213*
- >
- >**noise** - *101*
- >
- >**data** - *2E*
- >
- >**button1** - *0*
- >
- >**button2** - *1*
- >
- >**message_type** - *11*
- >
- >**group** - *61*
- >
- #### Description of the `first` byte:
- >Bit 7 (MSB) - Motion bit (0 - motionless, 1 - motion)
- >
- >Bit6 - B1 bit( 1- Button 1 press, 0- Button 1 release)
- >
- >Bit5 - Low Battery bit (1 - Battery OK, 0 - Low Battery)
- >
- >Bit 4 - B2 bit( 1- Button 2 press, 0- Button 2 release)
- >
- >Bit 3-2 - Message Status bits ( 00 - Supervision message, 11 - Event message)
- >
- >Bit 1-0(LSB) - The MSB bits of the ID.
- >
- ``` json
- lsb = bin(int(badge, 16))[2:4]
- ```
- ##### According to our example:
- >Bit 7 (MSB) - Motion bit - *1*
- >
- >Bit6 - B1 bit *0*
- >
- >Bit5 - Low Battery bit *1*
- >
- >Bit 4 - B2 bit *1*
- >
- >Bit 3-2 - Message Status bits *11*
- >
- >Bit 1-0(LSB) - The MSB bits of the ID -*11*
- >
- ``` json
- lsb = bin(int(badge, 16))[2:4]
- IDbadge=03F029
- lsb = bin(int("03F874", 16))[2:4] = 11
- ```
- `first`= hex((**motion**(1/0)|**button1**(1/0)|**battery**(0/1)|**button2**(0/1)|**message_type**(00/11)|**lsb**(__)), 2))[2:]
- ##### According to our example:
- >`first`= hex((1|0|1|1|11|11), 2))[2:] = BF
- >
- **_raw_** = **first**|**badge**[2:]|hex(**rssi**)[2:]|hex(**noise**)[2:]|**group**|**data**
- ##### According to our example:
- raw = BFF874D565612E
- >**_raw_** = BF|F874|D5|65|61|2E
- >
- ### Convert Temperature (*data* in BadgeMessage; *group* = _12_)
- temp_dict = {0: 806, 1: 798, 2: 790, 3: 781, 4: 772, 5: 764, 6: 755, 7: 745, 8: 736, 9: 727, 10: 717, 11: 707,
- 12: 697, 13: 687, 14: 677, 15: 667, 16: 656, 17: 646, 18: 635, 19: 625, 20: 614, 21: 604, 22: 593,
- 23: 582, 24: 572, 25: 561, 26: 550, 27: 539, 28: 529, 29: 518, 30: 507, 31: 497, 32: 486, 33: 476,
- 34: 466, 35: 456, 36: 445, 37: 435, 38: 426, 39: 416, 40: 406, 41: 396, 42: 387, 43: 378, 44: 368,
- 45: 359, 46: 350, 47: 342, 48: 333, 49: 324, 50: 316, 51: 308, 52: 300, 53: 292, 54: 284, 55: 277,
- 56: 270, 57: 262, 58: 255, 59: 249, 60: 242, 61: 236, 62: 229, 63: 223, 64: 217, 65: 211, 66: 205,
- 67: 200, 68: 194, 69: 189, 70: 184, 71: 179, 72: 174, 73: 169, 74: 165, 75: 160, 76: 156, 77: 151,
- 78: 147, 79: 143, 80: 139, -11: 882, -43: 989, -40: 984, -35: 974, -34: 972, -33: 970, -32: 967,
- -31: 965, -30: 962, -29: 959, -28: 956, -27: 953, -26: 950, -25: 947, -24: 943, -23: 940, -22: 936,
- -21: 932, -20: 928, -19: 924, -18: 919, -17: 914, -16: 909, -15: 904, -14: 899, -13: 893, -12: 888,
- -1: 814, -10: 876, -9: 870, -8: 863, -7: 857, -6: 850, -5: 843, -4: 836, -3: 829, -2: 821}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement