Pachube PHP Library documentation

This is a simple PHP (v5) library for accessing Pachube's create/retrieve/update/delete functions, returning feed information and realtime datastream values, easily creating configurable graphs in your webpages and Google maps of individual feeds, text-based searching for feeds, etc.

Available here: http://community.pachube.com/files/Pachube_PHP_library.zip - contains "pachube_functions.php" for all feed functions and "example.php" which demonstrates the functions (and generates the documentation found below).

Error reporting is pretty basic at the moment - in most cases functions return blank rather than bad values in the event that something goes wrong - but should be improved over time. If you would be interested to contribute to the library the code is hosted here for community-based collaborative development: http://github.com/uh/pachube_php/

Documentation

  • Create a Pachube object with your API key:
    $pachube = new Pachube($api_key);

    Returns:
    $pachube object


  • Work with an environment (returned as an associative array):
    $environment = $pachube->environment( $feed_id );

    Returns:
    $environment['description']: A simple low tech Building Management System, built using Arduino and an ethernet shield. At the moment it only serves sensor data.
    $environment['status']: live
    $environment['location']['name']: office
    $environment['location']['lat']: 51.565980037
    $environment['location']['lon']: -0.100700855255
    $environment['location']['exposure']: indoor
    count($environment['datastreams']): 7
    $environment['datastreams']['2']['value']['current_value']: 303


  • Create graphs and maps using the $environment array:
    $pachube->showEnvironmentGraph($environment,1);

    Returns:
    powered by Pachube.com

    $pachube->showEnvironmentGraph($environment,2, 700, 250, "0000FF", false, false, "My configured graph title", "My datastream units", 6);

    Returns:
    powered by Pachube.com

    $pachube->showEnvironmentMap($environment, 500, 200, "GOOGLE_MAP_API_KEY");

    Returns:


  • Retrieve raw feed data via URL (e.g. http://www.pachube.com/api/504.csv [.json | .xml]):
    $data = $pachube->retrieveData ($url);

    Returns:
    327,895,303,0,0,0,12216


  • Retrieve raw feed data as CSV, using feed ID only:
    $data = $pachube->retrieveData ( $feed, "csv" );

    Returns:
    9,67,15


  • Retrieve raw feed data as JSON, using feed ID only:
    $data = $pachube->retrieveData ( $feed, "json" );

    Returns:


  • Retrieve raw feed data as EEML, using feed ID only:
    $data = $pachube->retrieveData ( $feed, "xml" );

    Returns:


  • Display a Pachube datastream graph without creating $environment:
    $pachube->showGraph ( $feed_id, $datastream_id );

    Returns:
    powered by Pachube.com


  • Display a configured Pachube datastream graph without creating $environment:
    $pachube->showGraph ( $feed_id, $datastream_id, 500, 300, "00FF00", true, true, "My configured graph title", "My datastream units", 6 );

    Returns:
    powered by Pachube.com


  • Create a new manual Pachube feed:
    $new_feed_id = $pachube->createFeed ( $title );

    Returns:
    $new_feed_id;


  • Delete a Pachube feed (note this is set to delete the feed we just created):
    $delete_status = $pachube->deletePachube ( $new_feed_id );

    Returns:
    HTTP status code (200 = good)


  • Update a manual feed with CSV:
    $update_status = $pachube->updatePachube ( $url, $data );

    Returns:
    HTTP status code (200 = good)


  • Update a manual feed with EEML:
    $update_status = $pachube->updatePachube ( $url, $data );

    Returns:
    HTTP status code (200 = good)


  • Retrieve history data as an array:
    $history = $pachube->retrieveHistory ( $url );

    Returns:
    Array( [0] => 867.0 [1] => 868.0 [2] => 880.0 [3] => 885.0 [4] => 885.0 [5] => 860.0 [6] => 857.0 [7] => 874.0 [8] => 844.0 [9] => 846.0 [10] => 845.0 [11] => 828.0 [12] => 793.0 [13] => 736.0 [14] => 770.0 [15] => 668.0 [16] => 714.0 [17] => 666.0 [18] => 577.0 [19] => 384.0 [20] => 525.0 [21] => 512.0 [22] => 509.0 [23] => 511.0 [24] => 510.0 [25] => 511.0 [26] => 512.0 [27] => 510.0 [28] => 511.0 [29] => 513.0 [30] => 511.0 [31] => 512.0 [32] => 512.0 [33] => 512.0 [34] => 513.0 [35] => 513.0 [36] => 146.0 [37] => 145.0 [38] => 146.0 [39] => 142.0 [40] => 145.0 [41] => 141.0 [42] => 141.0 [43] => 140.0 [44] => 141.0 [45] => 141.0 [46] => 142.0 [47] => 141.0 [48] => 142.0 [49] => 142.0 [50] => 142.0 [51] => 142.0 [52] => 142.0 [53] => 144.0 [54] => 155.0 [55] => 222.0 [56] => 375.0 [57] => 535.0 [58] => 639.0 [59] => 690.0 [60] => 738.0 [61] => 758.0 [62] => 767.0 [63] => 780.0 [64] => 788.0 [65] => 792.0 [66] => 798.0 [67] => 805.0 [68] => 810.0 [69] => 812.0 [70] => 824.0 [71] => 832.0 [72] => 816.0 [73] => 806.0 [74] => 824.0 [75] => 839.0 [76] => 875.0 [77] => 854.0 [78] => 845.0 [79] => 833.0 [80] => 864.0 [81] => 872.0 [82] => 885.0 [83] => 864.0 [84] => 797.0 [85] => 810.0 [86] => 851.0 [87] => 838.0 [88] => 850.0 [89] => 875.0 [90] => 867.0 [91] => 888.0 [92] => 903.0 [93] => 905.0 [94] => 863.0 [95] => 874.0 )


  • Retrieve lat/lon of feeds that contain a term as an array:
    $latitude_and_longitudes = $pachube->getLatLon("current cost");

    Returns:
    Array
    ([0] => Array ( [lat] => 52.4539172358 [lon] => 1.0368347168 )
    [1] => Array ( [lat] => [lon] => )
    [2] => Array ( [lat] => 54.7144674331 [lon] => -5.80339053646 )
    [3] => Array ( [lat] => [lon] => )
    [4] => Array ( [lat] => 52.0984915124 [lon] => -0.031156539917 )
    [5] => Array ( [lat] => 51.3926738893 [lon] => -0.736676752567 )
    [6] => Array ( [lat] => 50.7963584684 [lon] => -0.628417977132 )
    [7] => Array ( [lat] => 52.0172124778 [lon] => -4.8308300972 )
    [8] => Array ( [lat] => 51.4913190014 [lon] => -3.24093192816 )
    [9] => Array ( [lat] => 53.4612644541 [lon] => -2.24711179733 )
    )

AttachmentSize
Pachube_PHP_library.zip7.11 KB