Skip to content

Instantly share code, notes, and snippets.

const FEED_ID = "FEED_ID_HERE";
const API_KEY = "API_KEY_HERE";
function send_xively(body) { //take in csv value
local xively_url = "https://api.xively.com/v2/feeds/" + FEED_ID + ".csv"; //setup url for csv
server.log(xively_url);
server.log(body); //pring body for testing
local req = http.put(xively_url, {"X-ApiKey":API_KEY, "Content-Type":"text/csv", "User-Agent":"Xively-Imp-Lib/1.0"}, body); //add headers
local res = req.sendsync(); //send request
if(res.statuscode != 200) {
server.log("error sending message: "+res.body);
local index = 0;
local masterUART = array(100); //serial buffer
//these should be changed to non character values
local startbit = 124; //which is |
local endbit = 126; //which is ~
//uart initialization
function startUART()
{
hardware.configure(UART_57);
hardware.uart57.configure(19200, 8, PARITY_NONE, 1, NO_CTSRTS); //baud:19200, dataBits:8, parity, stopbit
agent.on("json", function(value) { //receive data from agent
server.log("agent is on");
//server.log(value); //uncomment to print the data first
hardware.uart57.write("\n" + value); //write data to UART
});
function get_xively() {
//wakeup
imp.wakeup(30.0, get_xively); //schedule when to wakeup again
local xively_url = "https://api.xively.com/v2/feeds/" + FEED_ID + ".json"; //format xively url
server.log(xively_url);
local getreq = http.get(xively_url, {"X-ApiKey":API_KEY, "User-Agent":"xively-Imp-Lib/1.0"}); //add headers
local res = getreq.sendsync(); //actuallty send request
if(res.statuscode != 200) {
const FEED_ID = "FEED_ID_HERE";
const API_KEY = "API_KEY_HERE";
function get_xively() {
//wakeup
imp.wakeup(30.0, get_xively); //schedule when to wakeup again
local xively_url = "https://api.xively.com/v2/feeds/" + FEED_ID + ".json"; //format xively url
server.log(xively_url);
local index = 0;
local masterUART = array(100); //serial buffer
//these should be changed to non character values
local startbit = 124; //which is |
local endbit = 126; //which is ~
//uart initialization
function startUART()
{
hardware.configure(UART_57);
hardware.uart57.configure(19200, 8, PARITY_NONE, 1, NO_CTSRTS); //baud:19200, dataBits:8, parity, stopbit
/*
##Testing Environment for Xively Arduino Tutorial##
This program is designed to test the sensing circuit created
in the Xively Wi-Fi tutorial. It tests the photocell as well as the
LED output. This sketch can be adapted to take sensor readings from any analog sensor.
Derived from basicSensorTestEnv by Calum Barnes and AnalogInput by Tom Igoe
By Calum Barnes 3-4-2013
MIT License - [http://opensource.org/licenses/MIT]
Copyright (c) 2013 Calum Barnes
Sample Xively Arduino Sketch
/**
* Xively Arduino sensor client example.
*
* This sketch demonstrates connecting an Arduino to Xively (https://xively.com),
* using the new Arduino library to send and receive data.
*
* Requirements
* * Arduino with Ethernet shield or Arduino Ethernet (board must use the
* Wiznet Ethernet chipset)
@xively-gists
xively-gists / WiFiXivelyTutorial.ino
Last active December 17, 2015 05:58
Arduino wifi tutorial code
/*
##Xively WiFi Sensor Tutorial##
This sketch is designed to take sensors (from photocell) and upload the values to Xively
at consistant intervals. At the same time it gets a setable value from Xively to adjust the brigthness
of an LED. This sketch is reusable and can be adapted for use with many different sensors.
Derived from Xively Ardino Sensor Client by Sam Mulube.
By Calum Barnes 3-4-2013
BSD 3-Clause License - [http://opensource.org/licenses/BSD-3-Clause]
Copyright (c) 2013 Calum Barnes
@xively-gists
xively-gists / RaspberryPiTutorial.py
Last active December 17, 2015 06:28
Xively Raspberry Pi tutorial 1
#!/usr/bin/env python
import os
import xively
import subprocess
import time
import datetime
import requests
# extract feed_id and api_key from environment variables