Electric Imp GroveStreams Example

Many GroveStreams users use Electric Imp to push their samples into GroveStreams, but they initially struggled with the Electric Imp Agent code.

We at GroveStreams put together an example that demonstrates how to program the Agent to push the data into GS. The example can be found here:
https://www.grovestreams.com/developers/getting_started_elec_imp_temp.html

By the way, we’re a new cloud based data logger with many capabilities. Small users can use us for free. Enjoy!

Thanks for sharing! If it’s alright with you and your team, we would like to pull this example into our reference library (with proper attribution).

Let me know if that’s OK and we can follow up over email to get more details for attribution, licensing, etc :slight_smile:

Yes, we’d love to be a part of the reference library. Ping me for whatever you need. Thanks!

Ahhh! The Adafruit tutorial strikes again! It’s always great to see services writing libraries for the Imp, so thanks! I’ll move the impTherm X2 over to GroveStreams and check it out!

We’ve written an Electric Imp blog post with a tutorial that follows the one above. See https://community.electricimp.com/blog/what-is-gs/

Hi, nice always looking for things like this. Simple and straight forward.

Is there a way to NOT use a SPI example but a simple script that communicate’s the build in features like imp.rssi(), hardware.voltage(),hardware.lightlevel().
I my case coding is not really my strongest side, hardware is.

Many ppl look at the code, use and modify it to there needs, and test it quick to get a feel how its working together.
Why base it on a SPI board, many don’t have. i prefer testing without connecting 1 wire, if it works ill figure it out :), and grab my soldering iron

Edit Typo

Let me take a stab at what you’re looking for and @mmills can correct me if I’m wrong.

In the device code, you’re basically going to remove everything except lines 99 to 102 and also will strip out the temperature leaving a simple (looping) device code of:
function poll(){ local data = { id = hardware.getimpeeid(), mac = imp.getmacaddress(), voltage = hardware.voltage()} agent.send("GroveStreams", data); imp.wakeup(20, poll); //Wakeup every 20 second and read data. Change this value to change your sample frequency. } poll();

In the agent code, you’ll want to remove line 59 since you will no longer be passing the temperature from the device:
url += "&" + TEMP_STREAM_ID + "=" + data.temp;

This does not give you the other readings (light level and rssi), but I’m hoping the above gives you the basis of what you’re looking for. To add the others, you would need to:

  1. Create those streams in GroveStreams in the same fashion as voltage and temperature were defined
  2. Modify the device code to pass that data to the agent in the “local data=” line
  3. Modify the agent code inserting these values in the URL being passed to GroveStreams (similar in fashion to how the voltage and temperature are passed – just re-insert line 59, but with the new stream name(s) and data point(s)).

Does this help?

I think this is what you want and what @ctmorrisonhvacsp is suggesting. Just change the API_KEY to yours.

Agent:
`
// GroveStreams Settings
API_KEY <- “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”; //Change This!!! Your GS Organization Secret API Key
COMP_NAME <- “Electric+Imp+Simple” //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 = "https"+"://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);
});
`

Device:
`
function readData(){

server.log("Sending data to Imp Cloud Agent");

//Gather and pass the data to the Electric Imp Agent running in the cloud
local data = { id = hardware.getimpeeid(), mac = imp.getmacaddress(), rssi = imp.rssi(), 
               voltage = hardware.voltage(), light = hardware.lightlevel()}
agent.send("GroveStreams", data);

imp.wakeup(20, readData); //Wakeup every 20 second and read data. Change this value to change your sample frequency.

}

//Begin executing program
readData();
`

@ctmorrisonhvacsp and @mmils Thank u for responding and the time u spend giving me this example , i got the first data results instantaneously :slight_smile: .

Greetz from Holland

@mmills
You made things very easy.
Thanks

@mmills - can we pull the GroveStreams library into a reference repo:

https://github.com/electricimp/reference

@beardedinventor - sure. We can whip up an Imp webservice library that wraps some of our web calls in the next couple of weeks.

@mmills

I also got my Imp working with Grovestreams thanks to your input on this discussion.

Thanks very much!

Hi all !

I don’t know why it’s not working in my case, I followed as mmills example.

You can see in the Picture N°1 that the three params light, rssi and voltage appear when I refresh the page but the three are empty.

and I also have an error “pic2”

Thanks for the help

I think the problem is around the secret api key. Did you use the right API key? It should be this one: Feed Put API Key (with auto-registration rights)

If that’s not it, turn on API Tracing (In the GS Studio, Click API Keys, Select the above API key, Click Engage API Tracing). Wait a while until an upload occurs and then paste the result here and I’ll look at it - but, remove the secret key, an other sensitive data, from the tracing before you post it here.

Thanks a lot mmills.

I found that while creating the organization I made a mistake and then the GS didn’t propose for me the API Key(with auto-registration rights).
Thanks a lot