Skip to content

Instantly share code, notes, and snippets.

@unforgiven512
Forked from darconeous/eagle-200-curl.md
Created April 22, 2022 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unforgiven512/50c05e1084116df4083d0b025b2c9cb0 to your computer and use it in GitHub Desktop.
Save unforgiven512/50c05e1084116df4083d0b025b2c9cb0 to your computer and use it in GitHub Desktop.
Eagle-200 Local Usage via CURL

Eagle-200 Local Usage via CURL

You can locally pull data from your Rainforest Eagle-200 using cURL.

Rainforest has published a local API document which explains the details of the protocol. But this particular document is about quickly getting to the point and giving you some cURL commands you can use to immediately start pulling out data.

Prerequisites

First, I'll assume that you have the following environment variables set:

  • EAGLE_CLOUD_ID: This is the "Cloud ID" printed on the label on the bottom of your Eagle-200.
  • EAGLE_INSTALL_CODE: This is the install code, or "IN" printed on the label on the bottom of your Eagle-200, under your MAC address.
  • EAGLE_ADDRESS: This is the IPv4 address of your Eagle-200.

Go ahead and set them in your terminal with some lines like this:

export EAGLE_CLOUD_ID=008123
export EAGLE_INSTALL_CODE=12349abc5678def0
export EAGLE_ADDRESS=192.168.32.73

Sending Commands

Commands are sent to the Eagle-200 as XML fragments. You can send these XML-fragment-commands to the Eagle-200 with a command line that looks something like this:

curl --anyauth \
    -u "${EAGLE_CLOUD_ID}:${EAGLE_INSTALL_CODE}" \
    -XPOST "http://${EAGLE_ADDRESS}/cgi-bin/post_manager" \
    -d '<XML-FRAGMENT-HERE>'

Device List

The first command you are likely going to want to use is the device_list command. You can use it like this:

curl --anyauth \
    -u "${EAGLE_CLOUD_ID}:${EAGLE_INSTALL_CODE}" \
    -XPOST "http://${EAGLE_ADDRESS}/cgi-bin/post_manager" \
    -d '<Command><Name>device_list</Name></Command>'

With this command, you should get a response that looks like this:

<DeviceList>
  <Device>
    <HardwareAddress>0x0012300123001230</HardwareAddress>
    <Manufacturer>Generic</Manufacturer>
    <ModelId>electric_meter</ModelId>
    <Protocol>Zigbee</Protocol>
    <LastContact>0x5ab5bd9b</LastContact>
    <ConnectionStatus>Connected</ConnectionStatus>
    <NetworkAddress>0x0000</NetworkAddress>
  </Device>
</DeviceList>

The key bit of information there is the value of HardwareAddress, which is 0x0012300123001230 in our case. Let's go ahead and put that in an environment variable, too:

export EAGLE_METER_ADDRESS=0x0012300123001230

Device Query

With this information in hand, we can query the meter to spill all of its information with the device_query command:

curl --anyauth \
    -u "${EAGLE_CLOUD_ID}:${EAGLE_INSTALL_CODE}" \
    -XPOST "http://${EAGLE_ADDRESS}/cgi-bin/post_manager" \
    -d '<Command>
    <Name>device_query</Name>
    <DeviceDetails>
      <HardwareAddress>'${EAGLE_METER_ADDRESS}'</HardwareAddress>
    </DeviceDetails>
    <Components><All>Y</All></Components>
    </Command>'

And here is an example of the output:

<Device>
  <DeviceDetails>
    <Name>Power Meter</Name>
    <HardwareAddress>0x0012300123001230</HardwareAddress>
    <NetworkInterface>0xdeafcafe0000beef</NetworkInterface>
    <Protocol>Zigbee</Protocol>
    <NetworkAddress>0x0000</NetworkAddress>
    <Manufacturer>Generic</Manufacturer>
    <ModelId>electric_meter</ModelId>
    <LastContact>0x5ab5be93</LastContact>
    <ConnectionStatus>Connected</ConnectionStatus>
  </DeviceDetails>
  <Components>
    <Component>
      <HardwareId></HardwareId>
      <FixedId>0</FixedId>
      <Name>Main</Name>
      <Variables>
        <Variable>
          <Name>zigbee:InstantaneousDemand</Name>
          <Value>1.016000 kW</Value>
        </Variable>
        <Variable>
          <Name>zigbee:Multiplier</Name>
          <Value>1</Value>
        </Variable>
        <Variable>
          <Name>zigbee:Divisor</Name>
          <Value>1000</Value>
        </Variable>
        <Variable>
          <Name>zigbee:CurrentSummationDelivered</Name>
          <Value>0.098000 kWh</Value>
        </Variable>
        <Variable>
          <Name>zigbee:CurrentSummationReceived</Name>
          <Value>0.000000 kWh</Value>
        </Variable>
        <Variable>
          <Name>zigbee:Price</Name>
          <Value>0.000000</Value>
        </Variable>
        <Variable>
          <Name>zigbee:TrailingDigits</Name>
          <Value>255</Value>
        </Variable>
        <Variable>
          <Name>zigbee:RateLabel</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Currency</Name>
          <Value>USD</Value>
        </Variable>
        <Variable>
          <Name>zigbee:PriceTier</Name>
          <Value>0</Value>
        </Variable>
        <Variable>
          <Name>zigbee:PriceStartTime</Name>
          <Value>Sat Jan  1 00:00:00 2000</Value>
        </Variable>
        <Variable>
          <Name>zigbee:PriceDuration</Name>
          <Value>0 min</Value>
        </Variable>
        <Variable>
          <Name>zigbee:Message</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:MessageId</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:MessageStartTime</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:MessageDurationInMinutes</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:MessagePriority</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:MessageConfirmationRequired</Name>
          <Value>N</Value>
        </Variable>
        <Variable>
          <Name>zigbee:MessageConfirmed</Name>
          <Value>N</Value>
        </Variable>
        <Variable>
          <Name>zigbee:BlockPeriodNumberOfBlocks</Name>
          <Value>0</Value>
        </Variable>
        <Variable>
          <Name>zigbee:BlockPeriodConsumption</Name>
          <Value>0.000000 kWh</Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block1Price</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block2Price</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block3Price</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block4Price</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block5Price</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block6Price</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block7Price</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block8Price</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block1Threshold</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block2Threshold</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block3Threshold</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block4Threshold</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block5Threshold</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block6Threshold</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block7Threshold</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:Block8Threshold</Name>
          <Value></Value>
        </Variable>
        <Variable>
          <Name>zigbee:BlockPeriodStart</Name>
          <Value>946684800</Value>
        </Variable>
        <Variable>
          <Name>zigbee:BlockPeriodDuration</Name>
          <Value>0 min</Value>
        </Variable>
        <Variable>
          <Name>zigbee:BlockThresholdMultiplier</Name>
          <Value>1</Value>
        </Variable>
        <Variable>
          <Name>zigbee:BlockThresholdDivisor</Name>
          <Value>1</Value>
        </Variable>
        <Variable>
          <Name>zigbee:BillingPeriodStart</Name>
          <Value>1521841883</Value>
        </Variable>
        <Variable>
          <Name>zigbee:BillingPeriodDuration</Name>
          <Value>61996836 min</Value>
        </Variable>
      </Variables>
    </Component>
  </Components>
</Device>

Presto! There are of course ways to query for specific individual values. Have a look at the local API manual for specific examples for how to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment