Author Topic: Vantage Vue Data in Java  (Read 2459 times)

0 Members and 1 Guest are viewing this topic.

Offline cowxchaser731

  • Member
  • *
  • Posts: 18
Vantage Vue Data in Java
« on: February 23, 2015, 11:50:33 AM »
Hello all,

I am starting a project to read data from my Vantage Vue console and hopefully design an interface for it.

I have a datalogger bought from Davis and am getting data ok through Cumulus with it set in serial mode.

When I get the data through my java program I am able to get some things ok (test, BARDATA, etc...) but reading the actual loop packet is causing me trouble.

I have read a ton of posts and websites but can't seem to click with the best way to do this. Anyone have any suggestions on how to get the data in a readable format? I've tried reading some of the python scripts out there but as python is not my strong suite I haven't been able to understand how to do it.

Any help is greatly appreciated! Thanks!


Offline SLOweather

  • Administrator
  • Forecaster
  • *****
  • Posts: 3373
    • http://www.sloweather.com
Re: Vantage Vue Data in Java
« Reply #1 on: February 23, 2015, 12:14:25 PM »

Offline cowxchaser731

  • Member
  • *
  • Posts: 18
Re: Vantage Vue Data in Java
« Reply #2 on: February 23, 2015, 12:42:45 PM »
Hi Sloweather,

I've read it a couple of times.
I first send a \n to wake up the console, and a TEST, to which I get TEST back from the console, which is good.

Then when I send a LOOP 1 I get a byte array with HEX values.

When I convert to ASCII I get something like this:



TEST

LOOYv>E^
 

N_


I just think I'm missing something along the way...

Thanks for your input!

Offline johnd

  • Forecaster
  • *****
  • Posts: 2614
    • www.weatherstations.co.uk
Re: Vantage Vue Data in Java
« Reply #3 on: February 23, 2015, 12:52:57 PM »
You need to parse the binary values into the individual values/fields as shown in the LOOP record schema. In other words you can't just convert to text/ascii, but you must deconstruct the LOOP record into its constituent binary values and then process each individual value as required.
« Last Edit: February 23, 2015, 01:02:32 PM by johnd »
Prodata Weather Systems
Prodata's dedicated Davis EnviroMonitor website
UK Davis Premier Dealer - All Davis stations, accessories and spares
Littleport, Ely, Cambs UK

Offline cowxchaser731

  • Member
  • *
  • Posts: 18
Re: Vantage Vue Data in Java
« Reply #4 on: February 23, 2015, 01:05:26 PM »
Thanks Johnd,

I'll have to read up how to do that in java. Makes me think I'm not getting what I should to be able to convert it over.


Offline johnd

  • Forecaster
  • *****
  • Posts: 2614
    • www.weatherstations.co.uk
Re: Vantage Vue Data in Java
« Reply #5 on: February 23, 2015, 01:14:54 PM »
Makes me think I'm not getting what I should to be able to convert it over.

No reason to think that it's not coming over OK - superficially looks OK with the leading 'LOO'. Remember that if you're just trying to map each individual byte to an Ascii character then many of them may be ending up as nonprinting characters. But you're not really going to see until you have a Java class whose individual members map to the elements of the LOOP structure (or maybe you can create a Structure in Java as in .Net as an alternative to a class - sorry I don't speak Java so I don't know for sure).
Prodata Weather Systems
Prodata's dedicated Davis EnviroMonitor website
UK Davis Premier Dealer - All Davis stations, accessories and spares
Littleport, Ely, Cambs UK

Offline cowxchaser731

  • Member
  • *
  • Posts: 18
Re: Vantage Vue Data in Java
« Reply #6 on: February 23, 2015, 01:32:49 PM »
Thanks Johnd, makes sense.

I guess I'm having the most trouble trying to visualize how it all fits together:
How to get the data over properly (looks like I am but is it best to get as HEX, ASCII, binary, int,etc...?)
If it's binary I need to figure out how to get those values properly in java
How to deconstruct the loop packet.

The davis document is helpful in saying what to look at but not necessarily how to accomplish it.

Are you aware of any sites that talk more about these processes or have examples? I can somewhat read .net (c++ and c#) as they are very similar to java. Just slightly different terminology

Thanks again for your input!
« Last Edit: February 23, 2015, 01:37:16 PM by cowxchaser731 »

Offline SLOweather

  • Administrator
  • Forecaster
  • *****
  • Posts: 3373
    • http://www.sloweather.com

Offline ericfynne

  • Contributor
  • ***
  • Posts: 138
Re: Vantage Vue Data in Java
« Reply #8 on: February 23, 2015, 02:27:41 PM »
As John says, the LOOP data is in binary, not ASCII. Some of the values are single bytes, so you can access them directly, so if your loop data is in a byte array called 'loopdata', inside humidity for example is just loopdata[11]. Some of the values are two byte integers, LSB then MSB. So to extract outside temperature, for example, you use loopdata[12] + (loopdata[13] *256). The value is actually sent in tenths of a degree F, so to get the actual temperature you then divide that integer by 10.

Eric.

Offline cowxchaser731

  • Member
  • *
  • Posts: 18
Re: Vantage Vue Data in Java
« Reply #9 on: February 23, 2015, 03:45:22 PM »
Hi Eric,

Thanks, that was extremely helpful!

I was able to get the inside humidity, I am still having trouble with the outside temperature.

So when I run something similar to what you described ( use loopdata[12] + (loopdata[13] *256) )

I get these values.

In position 12 I have: -35
In position 13 I have: 0

So I get a result of
Inside Humidity: 28
Outside temperature: -35

Here's a snippet of what I am getting when I read out the entire packet: (positions 7 - 14)
Array 7-117
Array 8-118
Array 9--84
Array 10-2
Array 11-28
Array 12--35
Array 13-0
Array 14-0

This doesn't seem right, it is about 20 degrees out currently. Am I missing something else?

I appreciate everyone's help, it has been very useful! Thanks again!

Offline ericfynne

  • Contributor
  • ***
  • Posts: 138
Re: Vantage Vue Data in Java
« Reply #10 on: February 23, 2015, 04:04:45 PM »
Treat the bytes as unsigned. It's not -35, it's 221. 221/10 = 22.1 degrees.

Treat the result of combining the bytes as a signed 16-bit number.

Eric
« Last Edit: February 23, 2015, 04:11:02 PM by ericfynne »

Offline cowxchaser731

  • Member
  • *
  • Posts: 18
Re: Vantage Vue Data in Java
« Reply #11 on: February 23, 2015, 05:28:16 PM »
Ah I got it,

One problem was that java doesn't inherently deal well with unsigned numbers. You have to do some finagling to get everything converted over.
        //Monthly Rainfall
   //Convert first number from unsigned
      String x = in.get(52).toString();
      float i = Float.parseFloat(x);
      byte b = (byte) i;
      float i2 = b & 0xFF;

Still working on it but am liking the results that I am getting better:
************************************
Inside Humidity: 28
Inside temperature: 68.0
Outside temperature: 22.0
Monthly Rain Total: 0.69
************************************

Thank you all so much for your help, I think I got the right push I needed to make more progress on this!


Offline ericfynne

  • Contributor
  • ***
  • Posts: 138
Re: Vantage Vue Data in Java
« Reply #12 on: February 24, 2015, 03:43:09 AM »
One problem was that java doesn't inherently deal well with unsigned numbers. You have to do some finagling to get everything converted over.
The usual way to do this is to cast the byte to a longer type, such as an int:

int i = b & 0xFF;

Eric

Offline cowxchaser731

  • Member
  • *
  • Posts: 18
Re: Vantage Vue Data in Java
« Reply #13 on: February 25, 2015, 11:38:43 AM »
Hi Eric,

I agree and usually I will caste to an integer, but I want the number to 2 decimal places so I use a float in this case.


Offline Josiah

  • Add-InWx Software Author
  • Forecaster
  • *****
  • Posts: 439
    • Add-InWx
Re: Vantage Vue Data in Java
« Reply #14 on: February 25, 2015, 03:06:27 PM »
You do need to handle the Loop packets as a byte array. It also helps to put it thru the CRC function before trying to parse it for data.

I don't do any Java programming but this may help.
It's the VB.net code that I was using for Add-InWx before moving to C#.
Sorry for the lack of comments, But it should be pretty straight forward. The "ProcessData" Subroutine takes the Station's "Loop" packet as a byte array then parses it.
The "CRC_Check" function will return a 0 if the packet is good, any other number returned signifies that the data packet was corrupted during transmission.

oh, the values in the CRC table are declared in HEX. VB.net doesn't like the "0x" prefix, but instead it takes the "&H".

Code: [Select]
Private Sub ProcessData(ByRef DataToProcess As Byte())
        'Now Here's Where We start Pullling The Data values out of the recived data string
        If DataToProcess.Count = 99 Then 'Check to see if the data string contains anything
            Dim CRC_Val As UShort = CRC_Check(DataToProcess) ' Put the Byte array thru the CRC function
            If CRC_Val = 0 Then
                WXData.TempOutCur.Value = BitConverter.ToInt16(DataToProcess, 12) * 0.1 'Out Temp
                WXData.TempOutCur.TimeOfValue = DateTime.Now
                WXData.TempInCur.Value = BitConverter.ToInt16(DataToProcess, 9) * 0.1 'In Temp
                WXData.TempInCur.TimeOfValue = DateTime.Now
                WXData.WindSpeed.Value = Convert.ToInt32(DataToProcess(14)) 'Wind Speed
                WXData.WindSpeed.TimeOfValue = DateTime.Now
                WXData.WindBearing.Value = BitConverter.ToInt16(DataToProcess, 16) 'Wind Bearing
                WXData.WindBearing.TimeOfValue = DateTime.Now
               
                WXData.BarometerCur.Value = Decimal.Round(Convert.ToDecimal(BitConverter.ToInt16(DataToProcess, 7) / 1000), 2)
                WXData.BarometerCur.TimeOfValue = DateTime.Now
                WXData.RainTodayTotal.Value = BitConverter.ToInt16(DataToProcess, 50) * 0.01    'Today's Precip
                WXData.RainTodayTotal.TimeOfValue = DateTime.Now
                WXData.RainLongTermTotal.Value = BitConverter.ToInt16(DataToProcess, 54) * 0.01 'Total Precip This Year
                WXData.RainLongTermTotal.TimeOfValue = DateTime.Now
                WXData.HumidityOutCur.Value = Convert.ToInt32(DataToProcess(33)) 'OutHumidity
                WXData.HumidityOutCur.TimeOfValue = DateTime.Now


                If Convert.ToInt32(DataToProcess(43)) <> 255 Then
                    WXData.UVIndex.Value = Convert.ToInt32(DataToProcess(43)) * 0.1 'UV Index
                    WXData.UVIndex.TimeOfValue = DateTime.Now
                End If

                WXData.SolarRaidiation.Value = BitConverter.ToInt16(DataToProcess, 44) 'Solar Radiation
                WXData.SolarRaidiation.TimeOfValue = DateTime.Now

                WXData.LastUpdated = DateTime.Now
                Status = "Updated"
            Else
                Status = "CRC Check failed"
            End If
        Else
            Status = "Data Length Is Invalid."
        End If
End Sub

Private Shared Function CRC_Check(ByRef Data_Array As Byte()) As UShort
        Dim crc As UShort = 0
        For Each Tempbyte As Byte In Data_Array
            crc = CRC_Table((crc >> 8) Xor Tempbyte) Xor ((crc And &HFF) << 8)
        Next
        Return crc
End Function

Private Shared CRC_Table() As UShort = {&H0, &H1021, &H2042, &H3063, &H4084, &H50A5, &H60C6, &H70E7,
        &H8108, &H9129, &HA14A, &HB16B, &HC18C, &HD1AD, &HE1CE, &HF1EF,
        &H1231, &H210, &H3273, &H2252, &H52B5, &H4294, &H72F7, &H62D6,
        &H9339, &H8318, &HB37B, &HA35A, &HD3BD, &HC39C, &HF3FF, &HE3DE,
        &H2462, &H3443, &H420, &H1401, &H64E6, &H74C7, &H44A4, &H5485,
        &HA56A, &HB54B, &H8528, &H9509, &HE5EE, &HF5CF, &HC5AC, &HD58D,
        &H3653, &H2672, &H1611, &H630, &H76D7, &H66F6, &H5695, &H46B4,
        &HB75B, &HA77A, &H9719, &H8738, &HF7DF, &HE7FE, &HD79D, &HC7BC,
        &H48C4, &H58E5, &H6886, &H78A7, &H840, &H1861, &H2802, &H3823,
        &HC9CC, &HD9ED, &HE98E, &HF9AF, &H8948, &H9969, &HA90A, &HB92B,
        &H5AF5, &H4AD4, &H7AB7, &H6A96, &H1A71, &HA50, &H3A33, &H2A12,
        &HDBFD, &HCBDC, &HFBBF, &HEB9E, &H9B79, &H8B58, &HBB3B, &HAB1A,
        &H6CA6, &H7C87, &H4CE4, &H5CC5, &H2C22, &H3C03, &HC60, &H1C41,
        &HEDAE, &HFD8F, &HCDEC, &HDDCD, &HAD2A, &HBD0B, &H8D68, &H9D49,
        &H7E97, &H6EB6, &H5ED5, &H4EF4, &H3E13, &H2E32, &H1E51, &HE70,
        &HFF9F, &HEFBE, &HDFDD, &HCFFC, &HBF1B, &HAF3A, &H9F59, &H8F78,
        &H9188, &H81A9, &HB1CA, &HA1EB, &HD10C, &HC12D, &HF14E, &HE16F,
        &H1080, &HA1, &H30C2, &H20E3, &H5004, &H4025, &H7046, &H6067,
        &H83B9, &H9398, &HA3FB, &HB3DA, &HC33D, &HD31C, &HE37F, &HF35E,
        &H2B1, &H1290, &H22F3, &H32D2, &H4235, &H5214, &H6277, &H7256,
        &HB5EA, &HA5CB, &H95A8, &H8589, &HF56E, &HE54F, &HD52C, &HC50D,
        &H34E2, &H24C3, &H14A0, &H481, &H7466, &H6447, &H5424, &H4405,
        &HA7DB, &HB7FA, &H8799, &H97B8, &HE75F, &HF77E, &HC71D, &HD73C,
        &H26D3, &H36F2, &H691, &H16B0, &H6657, &H7676, &H4615, &H5634,
        &HD94C, &HC96D, &HF90E, &HE92F, &H99C8, &H89E9, &HB98A, &HA9AB,
        &H5844, &H4865, &H7806, &H6827, &H18C0, &H8E1, &H3882, &H28A3,
        &HCB7D, &HDB5C, &HEB3F, &HFB1E, &H8BF9, &H9BD8, &HABBB, &HBB9A,
        &H4A75, &H5A54, &H6A37, &H7A16, &HAF1, &H1AD0, &H2AB3, &H3A92,
        &HFD2E, &HED0F, &HDD6C, &HCD4D, &HBDAA, &HAD8B, &H9DE8, &H8DC9,
        &H7C26, &H6C07, &H5C64, &H4C45, &H3CA2, &H2C83, &H1CE0, &HCC1,
        &HEF1F, &HFF3E, &HCF5D, &HDF7C, &HAF9B, &HBFBA, &H8FD9, &H9FF8,
        &H6E17, &H7E36, &H4E55, &H5E74, &H2E93, &H3EB2, &HED1, &H1EF0}

« Last Edit: February 25, 2015, 03:11:00 PM by Josiah »