The Energy Detective Forums
December 14, 2017, 11:20:07 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: New TED Support forum launched!!
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Posting to a 3rd party server
TedDev
TED Software Developent
Administrator
Full Member
*****
Posts: 158


« on: February 24, 2011, 09:11:06 AM »

Starting with gateway version 400 and later, itís also possible to post data to a 3rd party server. This will allow developers to create remote services that can receive TED5000 data, without requiring end users to place their TED5000 on the internet.

The latest firmware and release notes is available here: http://forums.theenergydetective.com/index.php/topic,3.0.html

A PDF Version of this API is now available: http://files.theenergydetective.com/docs/TED5000ThirdPartyPostingAPI-R452.pdf

Technical Description
------------------------------------

Activation
==================

To configure the TED5000 to post to a 3rd party service, the following steps will need to be executed:

1. User selects "Activate Energy Posting" from the main menu.
2. User is prompted with a screen to enter 3rd party activation information:
-  URL of the authentication service.
-  Unique Identifier (provided by the 3rd party) to uniquely identify this ted on their system.  This can be as simple at the GW ID, or a password - 20 character max

A disclaimer about data security will also be presented via this popup, activation means they acknowledge the privacy risks.

3. User hits submit.  TED5000 makes a POST request to the 3rd party authentication service sending the unique identifier supplied in section 2.
XML Sent will be:

<ted5000Activation>
                <Gateway>210000</Gateway>
                <Unique>123456</Unique>
</ted5000Activation>

Gateway is the hardware identifier (Serial Number) of the unit making the request
Unique is the unique identifier that was supplied in step 2. This is optional and is meant as an extra security token to be provided to the 3rd party service if they wish to use it.

4. The activation service will respond back w/ the following

<ted500ActivationResponse>
                <PostServer>www.theenergydetective.com</PostServer >
                <UseSSL>true</UseSSL >
                <PostPort>443</PostPort >
                <PostURL>/postdata.cgi</PostURL>
                <AuthToken>MySecurityToten</AuthToken>
                <PostRate>10</PostRate>
</ted500ActivationResponse>

PostServer- The ip address or dns resolvable name of the server (80 character max)
PostPort - the port that the server is running on
PostURL - the path of the service receiving the post (80 character max)
UseSSL - whether or not to post data via SSL
AuthToken- Unique token provided by the 3rd party used to as an authentication mechanism when data is submitted by the TED5000 (optional) (20 character max)
PostRate - The number of  minutes between data posts. (1 - 15)

Activation can be performed by the user more than once.

Data
======================

Once activated, the TED5000 will begin to post the following data to the service defined above. The data will be in the following format:

------------------------------
<ted5000  GWID="200000" auth="MySecurityToken">
<MTU ID=100000 type="0">
                <cumulative timestamp="123456000"  watts="10000" rate="0.12345"/>
                <cumulative timestamp="123456060"  watts="10005" rate="0.12345"/>
                <cumulative timestamp="123456120"  watts="10010" rate="0.12345"/>
</MTU>
<MTU ID=100001 type="0">
                <cumulative timestamp="123456000"  watts="10000" rate="0.12345"/>
                <cumulative timestamp="123456060"  watts="10005" rate="0.12345"/>
                <cumulative timestamp="123456120"  watts="10010" rate="0.12345"/>
</MTU>
</ted5000>
--------------------------------

The "MTU" element will be repeated for each MTU in the system. If the gateway is only configured for 1 MTU, this block will only be repeated once.
                - ID: the unique hardware id of the MTU
                -type: the configuration type of the mtu (0=load, 1=solar, 2=net, 3=stand-alone, 5=stand-alone-net)

The "cumulative" element will be repeated for each queued "minute" reading since the last post. The device can store up to 15 "minute" readings . If more than 15 minutes elapse between successful posts, only last 15 minutes will be resent.
                -timestamp is the "Unix Epoch" based timestamp of the reading.
                -watts is the cumulative reading in watts by the MTU (since its creation) at the specified time.  Using the above example, each MTU is reporting 5watts of use since the previous minuteís data was sent (5W/min or 300W/hr (multiplied by 60))


  -cost is the "rate in effect" when the reading was made.

So, in the above example, for the first MTU, the readings show that the usage is 5 watts per minute for the last 3 minutes at a rate of $0.12345).

The service should respond w/ a HTTP 200 code if successful. Any code >= 300 will be considered to be an error code.

Posting statistics as well as error codes can be viewed on the stats.htm page (e.g. http://ted5000/stats.htm)

The error codes are:

Activation Error Codes:
0 - success
100 - Parsing error of activation xml file
101 - Timeout accessing activation file (also file not found)

Posting Error Codes:
These are the same response codes sent by the server. In addition, some codes are:

1000 - Socket error connecting to the server
2000 - Timeout posting data to the server
3100 - SSL Handshake timeout
4000 - Posting Data (Not an error code, just an indication that data is currently posting)

====

Quick Start
======================

To start your 3rd party posting development, it may be best to try a static xml file for activation, and a simple server-side PHP script to receive posts from your TED5000.

Below is a simple activation XML:

<ted500ActivationResponse>
 <PostServer>demo.theenergydetective.com</PostServer>
 <PostURL>/postData.php</PostURL>
 <UseSSL>F</UseSSL>
 <PostPort>80</PostPort>
 <AuthToken>myToken</AuthToken>
 <PostRate>1</PostRate>
 <SSLKey>NOT IMPLEMENTED</SSLKey>
</ted500ActivationResponse>

Copy this file to your web server. Be sure to test it in IE or Firefox to make sure its visible via your web connection:

i.e. http://demo.theenergydetective.com/act.xml

This url is what will be used for the "Activation URL" when you activate 3rd party posting via Footprints.


On the server, you can use the following PHP script to receive the XML post from the TED5000, and write the XML file to a directory.

postData.php
------
<?php

#change the /home/demo/xml path to the directory you wish to have xml
#posts written to.

$outp = fopen("/home/demo/xml/xmlfile." . date("YmdHis") . ".xml", "w");
fwrite($outp, $HTTP_RAW_POST_DATA);
fclose($outp);

?>

The URL path to this file is what is used for the PostServer and PostURL fields of the static activation xml file. Once activated you should see XML files being written within a few minutes.

« Last Edit: August 04, 2011, 11:30:41 PM by TedDev » Logged
Tom
Newbie
*
Posts: 5


« Reply #1 on: March 13, 2011, 03:49:12 PM »

Hello,

I am new to the forum. Thanks for this post, it's very helpful, I got my TED gateway to post data to a server. There are two things where I would appreciate points:

I can not find the posting statistics, I tried /stats.htm , /stats.html and no page to be seen; where is it?

Also, I used the value 10 as post rate, but I get updates every 31 seconds. Maybe the gateway isn't happy with the way the post transactions occur / finish?
HTTP/1.1 200 OK
Date: Mon, 14 Mar 2011 01:16:25 GMT

Thanks
Tom
 


PostRate - The number of  minutes between data posts. (1 - 15)

Posting statistics as well as error codes can be viewed on the stats.htm page (e.g. http://ted5000/stats.htm)

Logged
TedDev
TED Software Developent
Administrator
Full Member
*****
Posts: 158


« Reply #2 on: March 18, 2011, 06:47:28 AM »

I've attached an image showing where the stats box is on the stats.htm page.  http://ted5000/stats.htm isn't resolving for you, you may want to try the IP address of your TED5000 instead (if you see footprints, you should be able to see stats though).
« Last Edit: March 18, 2011, 06:59:07 AM by TedDev » Logged
TedDev
TED Software Developent
Administrator
Full Member
*****
Posts: 158


« Reply #3 on: March 18, 2011, 06:56:05 AM »

Edited first post - added an example server side receive script and activation xml.
Logged
dannyted
Jr. Member
**
Posts: 56


WWW
« Reply #4 on: March 20, 2011, 05:36:23 PM »

I have the data posting to my server now. I had a few questions:

1. Would you have you considered pushing some of the other data that is available in the ted5k/livedata.xml file?  Best option could be to let the user pick the fields they want as part of the activation. This data is a sample of what I was asking about:


2. Why did you choose the amount of watts since the gateway was powered vs watts since last post? Or some other factor?  I am just getting into development.  I suppose this value caught me off guard, but of course it is very usable.

thanks.

 


Logged

My Energy Blog - http://energymonitorblog.com
     --A site dedicated to discussing power saving information.

My Personal Blog - http://dannymullen.net

MyTed5000 - http://myted5k.com/danny/
     --Live Data from my ted5000

Like me on Facebook
http://www.facebook.com/pages/EnergyMonitorB
Tom
Newbie
*
Posts: 5


« Reply #5 on: April 06, 2011, 10:12:56 AM »

Thanks. After upgrading to gateway firmware 406, all worked as expected.

I've attached an image showing where the stats box is on the stats.htm page.  http://ted5000/stats.htm isn't resolving for you, you may want to try the IP address of your TED5000 instead (if you see footprints, you should be able to see stats though).

Logged
devguy
Newbie
*
Posts: 5


« Reply #6 on: June 21, 2011, 03:23:31 AM »

I agree with Danny, are there any plans to have the gateway out put other information?
Do you have to deduce the other fields based on watts since reset
Logged
TedDev
TED Software Developent
Administrator
Full Member
*****
Posts: 158


« Reply #7 on: June 21, 2011, 03:53:31 AM »

I apologize for the delayed response on this. I missed when it was posted.

1. Would you have you considered pushing some of the other data that is available in the ted5k/livedata.xml file?  Best option could be to let the user pick the fields they want as part of the activation. This data is a sample of what I was asking about:

Most of what is in livedata.xml (regarding power and cost) can be derived from the data we are posting.


2. Why did you choose the amount of watts since the gateway was powered vs watts since last post? Or some other factor?  I am just getting into development.  I suppose this value caught me off guard, but of course it is very usable.

The amount of watts we are sending is the number of watts read since the MTU left the factory. So even if you replaced gateway, the cumulative value would still be based on the MTU not the gateway.

Logged
checkers1811
Newbie
*
Posts: 13


« Reply #8 on: June 25, 2011, 06:50:53 AM »

I would like to add my vote for a bit more data to the 3rd party server.

Power line voltage.

Get rid of 'rate'? I can input that into the 3rd party server software.

Watts and Volts is the bare minimum.

Stick to the unique data that TED can provide.

Actually, I think the best answer is to pass the same XML data that you have in the Minute History.

<MINUTE>
<MTU>0</MTU>
<DATE>03/30/2010 20:17:00</DATE>
<POWER>8300</POWER>
<COST>125</COST>
<VOLTAGE>1188</VOLTAGE>
</MINUTE>

It is already formatted in the gateway. Just ship it.
« Last Edit: June 25, 2011, 07:24:18 AM by checkers1811 » Logged
dannyted
Jr. Member
**
Posts: 56


WWW
« Reply #9 on: June 25, 2011, 07:22:28 AM »

I second that.  I would like to have line voltage also, not sure exactly why but really having that and watts is the unique data ted can provide.
Logged

My Energy Blog - http://energymonitorblog.com
     --A site dedicated to discussing power saving information.

My Personal Blog - http://dannymullen.net

MyTed5000 - http://myted5k.com/danny/
     --Live Data from my ted5000

Like me on Facebook
http://www.facebook.com/pages/EnergyMonitorB
TedDev
TED Software Developent
Administrator
Full Member
*****
Posts: 158


« Reply #10 on: June 30, 2011, 04:11:23 PM »

Thanks on the suggestion on volts. We'll look into adding that.


There is also a new beta which contains another tweak to the new 'higher precision' watt data made available in R350.
http://www.theenergydetectiveforums.com/index.php/topic,296.0.html

« Last Edit: June 30, 2011, 05:11:14 PM by TedDev » Logged
bradvido
Newbie
*
Posts: 1


« Reply #11 on: September 30, 2011, 07:45:19 PM »

Your documentation says <ted500ActivationResponse />, where it should be <ted5000ActivationResponse />

five-hundred vs. five-thousand

I'm guessing this is just a typo, but I've found that some 3rd parties are indeed responding with the five-hundred element name.  TED seems to handle it fine, but should be consistent anyway.
Logged
ThermoMan
Newbie
*
Posts: 7


« Reply #12 on: June 26, 2013, 06:39:20 AM »

I've been using this feature for several months and been very happy with it. I even have an open source project that I've built around it.  But on June 3rd around 9pm I loaded firmware r499 (and Footprints r28) I didn't have time to check everything right after I loaded the new firmware and only now tracked down the problem to that date.  Also I had forgotten to re-enable posting after the update and just did that today.  But it is still not posting.

My stats.html tells me that I am getting Result "303" (which is not listed in the PDF).
ActivatedAct. StatusAttempts Success Result Last Timestamp
103603031372196340


I've done a restart on the unit with no improvement.  Do I need to revert to the previous firmware or is there something else I can try?

My open source code is on Github at
https://github.com/ThermoMan/TED-5000-Electricity-Tracking
The act.xml in there is demo, I have a real IP address in the 'working" version.


EDIT:  I have restored the previous version of the firmware (something that I would have called 'known good') and it's still not working.  The error 303 is supposedly some sort of redirection issue, but I cannot for the life of me track that down.  I can write a PHP page that tells the user what referrer he was redirected from and it says I'm making a "hard landing" (that is I was NOT redirected).  My .htaccess files have not changed for over a year.  I'm using a hosting service, but I can't help but wonder why it chose THAT day to change how only one of my hosted pages worked.
Any ideas on how to detect a redirection - or prove that there is NOT a redirection?

EDIT2: I also have tried the hard reset using the button on the side of the unit. No joy there either.

« Last Edit: July 19, 2013, 05:18:13 AM by ThermoMan » Logged
cjutzi
Newbie
*
Posts: 4


« Reply #13 on: August 04, 2013, 08:40:52 PM »


4. The activation service will respond back w/ the following

<ted500ActivationResponse>
                <PostServer>www.theenergydetective.com</PostServer >
                <UseSSL>true</UseSSL >
                <PostPort>443</PostPort >
                <PostURL>/postdata.cgi</PostURL>
                <AuthToken>MySecurityToten</AuthToken>
                <PostRate>10</PostRate>
</ted500ActivationResponse>


Just to help others out that might have wasted a bunch of time trying to figure this out..
THIS is not documented anywhere I have found.. I"m guessing only a few have not given up trying to make this work :-)

Logged
ThermoMan
Newbie
*
Posts: 7


« Reply #14 on: August 08, 2013, 07:09:38 PM »

It just struck me why my unit stopped posting.

Code:
<ted500ActivationResponse>
 <PostServer>http://MY_SERVER</PostServer>
 <PostURL>/elec/scripts/postData.php</PostURL>
 <UseSSL>F</UseSSL>
 <PostPort>80</PostPort>
 <AuthToken>myToken</AuthToken>
 <PostRate>1</PostRate>
 <SSLKey>NOT IMPLEMENTED</SSLKey>
</ted500ActivationResponse>

This is my exact XML file and it worked great until the last firmware update, but on re-reading the thread for the umpteenth time I finally got it into my head to check my 500/5000 and to my horror I see that I had "500" and NOT "5000" in my XML.

If the latest firmware got around to actually checking the XML framing then mine woudl have been rejected.  Although no explanation why it would have told me that is successfully set up the contact.

Later on I'll try using this.
Code:
<ted5000ActivationResponse>
 <PostServer>http://MY_SERVER</PostServer>
 <PostURL>/elec/scripts/postData.php</PostURL>
 <UseSSL>F</UseSSL>
 <PostPort>80</PostPort>
 <AuthToken>myToken</AuthToken>
 <PostRate>1</PostRate>
 <SSLKey>NOT IMPLEMENTED</SSLKey>
</ted5000ActivationResponse>
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!