B4R Question byte address to string

atiaust

Active Member
Licensed User
Longtime User
Hi All,

I am using multiple DS18B20 temp sensors on a Wemos D1 mini and sending the data to a B4J data logger.

Each DS18B20 has a unique 8 Byte address ie '28FF7881B11705E7'.

I am trying to get the last 2 bytes '05' and 'E7' as a string "05E7" to send to the B4J app so as to identify the sensor.

I have tried everything using byteconverter etc but I get 'casting errors' or 'Object converted to string, this is probably a programming error'.

Any one have any clues?

Thanks
 

atiaust

Active Member
Licensed User
Longtime User
Thanks Peter,

The string is stored in an 8 byte array that is read from the sensor during the OneWire read process. see Erel's tutorial

https://www.b4x.com/android/forum/threads/onewire-dallas-1-wire-protocol.66672/#content

Global address(8) as byte.

So my example above was just a string representation of the log for 'ROM' returned during the read..

I want to strip the last 2 bytes and put them into a string. Conversion is proving tricky in B4R.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Firstly sorry but I've not got any of my Arduinos or ESPs with me at current.
Can't you just read the 8 byte array into an array() and then read array(6) and array(7). I'm usually able to test what I'm thinking before hand, but as I've not currently got anything with me apart from my laptop, I can't really test what I'm thinking.

I should really keep an Arduino or an ESP with my laptop at all times, but I don't ;)
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
This is what I came up with.

B4X:
   Dim c(2) As Byte
    bc.ArrayCopy2(address,6,c,0,2)
    Dim addr2 As String = bc.HexFromBytes(c)
    Log("c =",addr2)

I think this will work for me.

Thanks
 
Upvote 0
Top