Skip to content

Instantly share code, notes, and snippets.

# Create an object from an eeml document
environment = Eeml::Environment.new_from_eeml(string_containing_eeml_representation)
# attributes available like this
puts environment.title
puts environment.description
puts environment.feed
# etc...
# alternatively would this be better?
@smulube
smulube / gist:2718463
Created May 17, 2012 12:06
Basic Cosm WebSocket example
<html>
<head>
<title>Socket Test</title>
</head>
<body>
<h1>Cosm Websocket Test</h1>
<p>Status: <span id="status"></span></p>
<p>Current value: <span id="current_value"></span></p>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
@smulube
smulube / gist:3347929
Created August 14, 2012 09:59
Sample multi datastream CSV
stream0,2012-05-01T00:00:00Z,1
stream0,2012-05-01T00:00:05Z,2
stream0,2012-05-01T00:00:06Z,3
stream0,2012-05-01T00:00:07Z,4
stream1,2012-05-01T00:00:00Z,1
stream1,2012-05-01T00:00:05Z,2
stream1,2012-05-01T00:00:06Z,3
stream1,2012-05-01T00:00:07Z,4
@smulube
smulube / automatic_cosm.php
Created October 30, 2012 09:59
Simple PHP script for converting WEL web energy logger XML for Cosm
<?
// set some variables we'll use later
$timezone_offset = '-05'; // set to your local timezone offset from UTC
$raw_url = "http://urltoyourdata.xml"; // replace with actual path to your published raw data
$title = "The title for your feed"; // the title for your Cosm feed
// Get raw data
$raw_xml = simplexml_load_file($raw_url);
<?
// set some variables we'll use later
$timezone_offset = '-06'; // set to your local timezone offset from UTC
$raw_url = "http://urltoyourdata.xml"; // replace with actual path to your published raw data
$title = "data logger"; // the title for your Cosm feed
$feed_id = 83211;
$api_key = "insert_api_key"; // this api key needs to have 'update' access to your feed
@smulube
smulube / cosm_currentcost.py
Last active October 12, 2015 14:58
Basic script to read data from a CurrentCost CC128 and post that data to Cosm
#!/usr/bin/env python
import serial
import xml.etree.ElementTree as ET
import sys
import requests
import json
import time
import syslog
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Cosm.h>
#define API_KEY "YOURAPIKEY" // your Cosm API key
#define FEED_ID YOURFEEDID // your Cosm feed ID
// MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
@smulube
smulube / gist:5798165
Created June 17, 2013 16:20
Upload data to Xively using Net::HTTP
require 'net/http'
require 'json'
require 'time'
feed_id = YOUR_FEED_ID
api_key = "YOUR_API_KEY"
payload = { :version => "1.0.0", :datastreams => [
{ :id => "Temperature", :at => Time.now.iso8601, :current_value => "17.2"}
]}.to_json
@smulube
smulube / gist:5830587
Created June 21, 2013 11:23
xively datapoints tests
import xively
import datetime
FEED_ID=123
API_KEY="123abc"
api = xively.XivelyAPIClient(API_KEY)
feed = api.feeds.get(FEED_ID)
@smulube
smulube / HmacUtils.java
Last active November 15, 2017 13:38
Java helper to generate a hex SHA1 HMAC suitable for generating device activation code for Xively.
// Copyright (c) 2003-2013, LogMeIn, Inc. All rights reserved.
// This is part of Xively4J library, it is under the BSD 3-Clause license.
package com.xively.client.utils;
import java.math.BigInteger;
import java.security.GeneralSecurityException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;