Emoncms & Python

Below is a small code example that will post updates to EmonCMS using Python –

#!bin/python
import requests

def postEmoncms(parameter_list):					# parameter_list is a dictionary
	
	host					=	'your.emoncms.host'			# Enter you host name or IP here
	emoncmsApi				=	'yourEmonCmsRwApiKey'		# This must be your EmonCMS RW API Key
	nodeName 				=	'nodeNameYouWantToUse'		# The name of the node you want to update with these values
	
	url 					= 	'http://' + host + '/emoncms/input/post'

	fullList				=	dict()
	fullList['node']		=	nodeName
	fullList['apikey']		=	emoncmsApi
	fullList['json']		=	str(parameter_list)
	
	http 					= 	requests.Session()
		
	r 						= 	http.post	(		url,
													params=fullList
											)
	return

def main():
	valuesToPost					=	dict()		# Create an empty dictionary to contain the values to post

	valuesToPost['youKeyName1']		=	1			# First Key Name and value
	valuesToPost['youKeyName2']		=	2			# Second Key Name and value
	valuesToPost['youKeyName3']		=	3			# Third Key Name and value

	postEmoncms(valuesToPost)						# pass the keys to the post function

if __name__ == "__main__":

	main() 

Currentcost Serial Cable

Some time ago my CurrentCost EnviR monitor stopped logging data to the attached Raspberry Pi. Initially I thought this was down to lack of input i.e. flat batteries in the OptiSmart Sensor. On checking this evening it appears that the serial cable, in particular the FTDI chip may have failed – checking around I’ve found the pinout for the cable so may have a go at making my own –

orange/white
orange
green/white (pin 7, data in to currentcost)
blue (pin 4, ground)
blue/white
green
brown/white
brown (pin 8, data out from currentcost)