Current Current History History Station Data Station Data CWOP Links CWOP Links Weather Underground Weather Underground

Decoding a Davis LOOP Packet

Overview

At this point we've got all the tools we need to start mapping the station data into the MODBUS register space. We'll also need some of the observations later for the derived calculations so we'll define a structure to collect them.

struct vp2_conditions {
    double temp;    // F
    double bar;     // inHg
    double hum;     // percent
    double wind;    // mph
    double rad;     // W/m^2
    double dew;     // F
    double den;     // kg/m^3
};			
			

I've configured the console to use United States customary units rather than metric only because they're more familiar. If you opt for metric, remember to adjust your constants.

Formatting Bit, Integer and Real Values

Using the protocol reference and the conversion tools the last section we just map the observations one by one.

void vp2_update(USHORT *pucRegBuffer) {

    unsigned char *ptr = (unsigned char *) usb_buffer();
    int i, modptr = 0;
    static struct vp2_conditions cond;
    
    /* 40001 int(1)   Barometer Trend (enumerated) */
    pucRegBuffer[modptr++] = SBTOB(3);

    /* 40002 float(2) Barometer (in Hg) */
    modptr += vp2_pack_float(cond.bar = (DBTOW(7) / 1000.0), &pucRegBuffer[modptr]);

    /* 40004 float(2) Inside Temperature (F) */
    modptr += vp2_pack_float(DBTOW(9) / 10.0, &pucRegBuffer[modptr]);
	
    ....
	
}

When the code is compiled, we should be able to retrieve values such as the outside temperature from the application using a utility like modpoll.

$ modpoll -m tcp -r 40008 -t 4:float -f 127.0.0.1

Observation Register Map

This station doesn't use any additional sensors but I've allocated space for them anyway. The complete observation register map looks like this:

Register Name Type Units Notes
40001 Barometer Trend int enumerated  
40002 Barometer float in Hg  
40004 Inside Temperature float F  
40006 Inside Humidity float %  
40008 Outside Temperature float F  
40010 Wind Speed float mph  
40012 10 Minute Average Wind Speed float mph  
40014 Wind Direction float degrees 0 indicates no value, 1..360
40016 Extera Temperature 1 float F Optional
40018 Extera Temperature 2 float F
40020 Extera Temperature 3 float F
40022 Extera Temperature 4 float F
40024 Extera Temperature 5 float F
40026 Extera Temperature 6 float F
40028 Extera Temperature 7 float F
40030 Soil Temperature 1 float F Optional
40032 Soil Temperature 2 float F
40034 Soil Temperature 3 float F
40036 Soil Temperature 4 float F
40038 Leaf Temperature 1 float F Optional
40040 Leaf Temperature 2 float F
40042 Leaf Temperature 3 float F
40044 Leaf Temperature 4 float F
40046 Outside Humidity float %  
40048 Extra Humidity 1 float % Optional
40050 Extra Humidity 2 float %
40052 Extra Humidity 3 float %
40054 Extra Humidity 4 float %
40056 Extra Humidity 5 float %
40058 Extra Humidity 6 float %
40060 Extra Humidity 7 float %
40062 Rain Rate float in/hr  
40064 UV Index float    
40066 Solar Radiation float W/m^2  
40068 Storm Rain float in  
40070 Start Date of Current Storm int   Year
40071 Month
40072 Day
40073 Day Rain float in  
40075 Month Rain float in  
40077 Year Rain float in  
40079 Day ET float in  
40081 Month ET float in  
40083 Year ET float in  
40085 Soil Moisture 1 float centibar Optional
40087 Soil Moisture 2 float centibar
40089 Soil Moisture 3 float centibar
40091 Soil Moisture 4 float centibar
40093 Leaf Wetness 1 int enumerated Optional, 0 .. 15 (very dry to very wet)
40094 Leaf Wetness 2 int enumerated
40095 Leaf Wetness 3 int enumerated
40096 Leaf Wetness 4 int enumerated
40097 Inside Alarms int bitmap  
40098 Rain Alarms int bitmap  
40099 Outside Alarms 1 int bitmap  
40100 Outside Alarms 2 int bitmap  
40101 Outside Humidity Alarms int bitmap  
40102 Extra Temperature/Humidity Alarms 1 int bitmap Optional
40103 Extra Temperature/Humidity Alarms 2 int bitmap
40104 Extra Temperature/Humidity Alarms 3 int bitmap
40105 Extra Temperature/Humidity Alarms 4 int bitmap
40106 Extra Temperature/Humidity Alarms 5 int bitmap
40107 Extra Temperature/Humidity Alarms 6 int bitmap
40108 Extra Temperature/Humidity Alarms 7 int bitmap
40109 Soil and Leaf Alarms 1 int bitmap Optional
40110 Soil and Leaf Alarms 2 int bitmap
40111 Soil and Leaf Alarms 3 int bitmap
40112 Soil and Leaf Alarms 4 int bitmap
40113 Transmitter Battery Status int enumerated 0 is ok
40114 Console Battery Voltage float V  
40116 Forecast Icons int bitmap  
40117 Forecast Rule int enumerated  
40118 Console Sunrise int hour 0..23
40119 int minute 0..59
40120 Console Sunset int hour 0..23
40121 int minute 0..59