// Electric Imp Quick Start Agent Code for GroveStreams
// A full "how to" guide for this agent can be found at https://www.grovestreams.com/developers/getting_started_elec_imp_temp.html
//
// License:
// Copyright 2014 GroveStreams LLC.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// GroveStreams Settings
API_KEY <- "YOUR_SECRET_API_KEY_HERE"; //Change This!!! Your GS Organization Secret API Key
COMP_NAME <- "Electric+Imp+Quick" //Optionally change. Your GS Component Name (URL encoded. The "+" indicates spaces)
RSSI_STREAM_ID <- "rssi"; //Optionally change. Your GS rssi stream ID
VOLTAGE_STREAM_ID <- "voltage" //Optionally change. Your GS voltage stream ID
LIGHT_STREAM_ID <- "light" //Optionally change. Your GS light stream ID
GroveStreams <- {}; // this makes a 'namespace'
class GroveStreams.Client {
constructor() {
}
function Put(data){
local url = "http"+"://grovestreams.com/api/feed?compId=" + data.mac;
url += "&compName=" + COMP_NAME + "+(" + data.mac + ")";
url += "&api_key=" + API_KEY;
url += "&" + RSSI_STREAM_ID + "=" + data.rssi;
url += "&" + LIGHT_STREAM_ID + "=" + data.light;
url += "&" + VOLTAGE_STREAM_ID + "=" + data.voltage;
//url += "&compTmplId=template1"; //Uncomment to auto register a new component based on the template with ID=template1
local headers = { "Connection":"close", "X-Forwarded-For" : data.mac };
local request = http.put(url, headers, "");
local response = request.sendsync();
if(response.statuscode != 200) {
server.log("error sending message: " + response.body);
return null;
}
}
}
client <- GroveStreams.Client();
//********************END GroveStreams********************
device.on("GroveStreams", function(data) {
server.log("Sending data to GS");
client.Put(data);
});