<commit_before>#!/usr/bin/env python
# modified from: http://pymodbus.readthedocs.org/en/latest/examples/synchronous-client.html

from pymodbus.client.sync import ModbusTcpClient as ModbusClient
import logging
import argparse
import subprocess
import time
import sys

def get_args():
	parser = argparse.ArgumentParser(description='Copies a given file')
	parser.add_argument('-s', dest='slave_addr', help='Address of the slave device', default='localhost', required=True)
	parser.add_argument('-d', dest='debug', help='Enable debugging', action="store_true", default=False)
	args = parser.parse_args()

	# if the -d flag is set (True), configure logging
	if args.debug:
		logging.basicConfig()
		log = logging.getLogger()
		log.setLevel(logging.DEBUG)

	# read arguments (the address of the server)
	return args

def enable_light(temp):
	"""
	Enables the red or green light, depending on the temp
	@param temp - the value of the temperature in degrees Fahrenheit * 100
	"""
	# Initialize pins for output
	subprocess.call(['gpio', 'mode', '0', 'out'])
	subprocess.call(['gpio', 'mode', '1', 'out'])

	# If higher, write 1 to red LED, if lower write 1 to green LED
	if int(temp) > 7400:
		subprocess.call(['gpio', 'write', '0', '1'])
		subprocess.call(['gpio', 'write', '1', '0'])
		print "GREATER"	
	else:
		subprocess.call(['gpio', 'write', '1', '1'])
		subprocess.call(['gpio', 'write', '0', '0'])
		print "LESS"
	print temp

def main():
	args = get_args()

	# connect to modbus slave
	client = ModbusClient(args.slave_addr, port=502)
	client.connect()

	# get value of holding registers (first has the temperature value)
	rr = client.read_holding_registers(0x00,1,unit=1)
	temp = rr.registers[0]
	try:
		while True:
			enable_light(temp)
			time.sleep(3)
	except KeyboardInterrupt:
		subprocess.call(['gpio', 'write', '0', '0'])
		subprocess.call(['gpio', 'write', '1', '0'])<commit_msg>reads changing values from the remote sensor<commit_after>#!/usr/bin/env python
# modified from: http://pymodbus.readthedocs.org/en/latest/examples/synchronous-client.html

from pymodbus.client.sync import ModbusTcpClient as ModbusClient
import logging
import argparse
import subprocess
import time
import sys

def get_args():
	parser = argparse.ArgumentParser(description='Copies a given file')
	parser.add_argument('-s', dest='slave_addr', help='Address of the slave device', default='localhost', required=True)
	parser.add_argument('-d', dest='debug', help='Enable debugging', action="store_true", default=False)
	args = parser.parse_args()

	# if the -d flag is set (True), configure logging
	if args.debug:
		logging.basicConfig()
		log = logging.getLogger()
		log.setLevel(logging.DEBUG)

	# read arguments (the address of the server)
	return args

def enable_light(temp):
	"""
	Enables the red or green light, depending on the temp
	@param temp - the value of the temperature in degrees Fahrenheit * 100
	"""
	# Initialize pins for output
	subprocess.call(['gpio', 'mode', '0', 'out'])
	subprocess.call(['gpio', 'mode', '1', 'out'])

	# If higher, write 1 to red LED, if lower write 1 to green LED
	if int(temp) > 7500:
		subprocess.call(['gpio', 'write', '0', '1'])
		subprocess.call(['gpio', 'write', '1', '0'])
		print "GREATER"	
	else:
		subprocess.call(['gpio', 'write', '1', '1'])
		subprocess.call(['gpio', 'write', '0', '0'])
		print "LESS"
	print temp

def main():
	args = get_args()

	# connect to modbus slave
	client = ModbusClient(args.slave_addr, port=502)
	client.connect()

	try:
		while True:
			# get value of holding registers (first has the temperature value)
			rr = client.read_holding_registers(0x00,1,unit=1)
			temp = rr.registers[0]
			enable_light(temp)
			time.sleep(3)
	except KeyboardInterrupt:
		subprocess.call(['gpio', 'write', '0', '0'])
		subprocess.call(['gpio', 'write', '1', '0'])
{'fraction_non_alphanumeric': 0.15211119853134014, 'fraction_numerical': 0.01730920535011802, 'mean_word_length': 4.987441130298273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3697389', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1262, 'n_words': 375}