A atiaust Active Member Licensed User Longtime User Jan 6, 2018 #1 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
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
Peter Simpson Expert Licensed User Longtime User Jan 6, 2018 #2 Hello @atiaust, try using ByteConverter. Code: Copy Sub Process_Globals Private Address As String = "28FF7881B11705E7" End Sub Private Sub AppStart Private BC As ByteConverter Log(BC.SubString(Address, 12)) End Sub Enjoy... Upvote 0
Hello @atiaust, try using ByteConverter. Code: Copy Sub Process_Globals Private Address As String = "28FF7881B11705E7" End Sub Private Sub AppStart Private BC As ByteConverter Log(BC.SubString(Address, 12)) End Sub Enjoy...
A atiaust Active Member Licensed User Longtime User Jan 6, 2018 #3 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
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.
Peter Simpson Expert Licensed User Longtime User Jan 7, 2018 #4 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
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
A atiaust Active Member Licensed User Longtime User Jan 7, 2018 #5 This is what I came up with. Code: Copy 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
This is what I came up with. Code: Copy 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