<commit_before>import spidev
import json
import urllib2
import RPi.GPIO as GPIO
import dht11
import time

from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

spi = spidev.SpiDev()
spi.open(0, 0)

instance = dht11.DHT11(pin=14)

def getAdc(channel):
        if channel > 7 or channel < 0:
                return -1

        r = spi.xfer([1, 8 + channel << 4, 0])
        adcOut = ((r[1] & 3) << 8) + r[2]
        solo = int(round(adcOut / 10.24))
        print 'ADC Output: {0:4d} Umidade do solo: {1:3}%'.format(adcOut, solo)
        sleep(0.1)
        return solo

def postData(temperatura, umidade, acelerometro, solo)        
        data = { "Temperatura": temperatura, "Umidade": umidade, "Acelerometro": acelerometro, "Solo": solo }
        req = urllib2.Request('https://homologacao.imap.org.br/prevent/api/store')
        req.add_header('Content-Type', 'application/json')
        response = urllib2.urlopen(req, json.dumps(data))
        
while True:
        solo = getAdc(5)
        
        result = instance.read()        
        temperature = result.is_valid() ? result.temperature : null        
        humidity = result.is_valid() ? result.humidity : null                
        
        time.sleep(10000)
        
        postData(temperature, humidity, 0, solo)
                
<commit_msg>DHT11 + Soil + HTTP<commit_after>import spidev
import json
import urllib2
import RPi.GPIO as GPIO
import dht11
import time

from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

spi = spidev.SpiDev()
spi.open(0, 0)

instance = dht11.DHT11(pin=14)

def getAdc(channel):	
        if channel > 7 or channel < 0:
                return -1

        r = spi.xfer([1, 8 + channel << 4, 0])
        adcOut = ((r[1] & 3) << 8) + r[2]
        solo = int(round(adcOut / 10.24))
        sleep(0.1)
        return 100 - solo

def postData(form):       
        req = urllib2.Request('https://homologacao.imap.org.br/prevent/api/store')
        req.add_header('Content-Type', 'application/json')
        response = urllib2.urlopen(req, json.dumps(form))
        
while True:
        result = instance.read()                                
        
	if result.is_valid():
		solo = getAdc(5)

	        data = { "Temperatura":	 result.temperature, "Umidade": result.humidity, "Acelerometro": 0, "Solo": solo }
	
		print(data) 
	
	        postData(data)

	time.sleep(1)


{'fraction_non_alphanumeric': 0.12946979038224415, 'fraction_numerical': 0.03247020139745171, 'mean_word_length': 2.2367021276595747, 'pattern_counts': {'":': 8, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '1403690', 'n_tokens_mistral': 905, 'n_tokens_neox': 848, 'n_words': 189}