Laurence Daxes
Published © MIT

BeagleBone Green Temperature Monitor on Artik Cloud

Publish Grove Temperature Sensor values collected by a BeagleBone Green to Artik Cloud.

IntermediateFull instructions provided2 hours1,783
BeagleBone Green Temperature Monitor on Artik Cloud

Things used in this project

Hardware components

SeeedStudio BeagleBone Green
BeagleBoard.org SeeedStudio BeagleBone Green
×1
Seeed Studio Grove I2C ADC
×1
Seeed Studio Grove Temperature Sensor
×1

Software apps and online services

ARTIK Cloud for IoT
Samsung ARTIK Cloud for IoT

Story

Read more

Schematics

20160928_000644.jpg

Code

read-temp.py

Python
import time
import math
import grove_i2c_adc
import Adafruit_BBIO.GPIO as GPIO
 
BUZZER = "P9_22"            # GPIO P9_22
GPIO.setup(BUZZER, GPIO.OUT)
# The threshold to turn the buzzer on 28 Celsius
THRESHOLD_TEMPERATURE = 28
adc = grove_i2c_adc.I2cAdc()
#   The argument in the read_temperature() method defines which Grove board(Grove Temperature Sensor) version you have connected.
#   Defaults to 'v1.2'. eg.
#       temp = read_temperature('v1.0')          # B value = 3975
#       temp = read_temperature('v1.1')          # B value = 4250
#       temp = read_temperature('v1.2')          # B value = 4250
def read_temperature(model = 'v1.2'):
    "Read temperature values in Celsius from Grove Temperature Sensor"
    # each of the sensor revisions use different thermistors, each with their own B value constant
    if model == 'v1.2':
        bValue = 4250  # sensor v1.2 uses thermistor ??? (assuming NCP18WF104F03RC until SeeedStudio clarifies)
    elif model == 'v1.1':
        bValue = 4250  # sensor v1.1 uses thermistor NCP18WF104F03RC
    else:
        bValue = 3975  # sensor v1.0 uses thermistor TTC3A103*39H
        
    total_value = 0
    for index in range(20):
        sensor_value = adc.read_adc()
        total_value += sensor_value
        time.sleep(0.05)
    average_value = float(total_value / 20)
    # Transform the ADC data into the data of Arduino platform.
    sensor_value_tmp = (float)(average_value / 4095 * 2.95 * 2 / 3.3 * 1023)
    resistance = (float)(1023 - sensor_value_tmp) * 10000 / sensor_value_tmp
    temperature = round((float)(1 / (math.log(resistance / 10000) / bValue + 1 / 298.15) - 273.15), 2)
    return temperature
# Function: If the temperature sensor senses the temperature that is up to the threshold you set in the code, the buzzer is ringing for 1s.
# Hardware: Grove - I2C ADC, Grove - Temperature Sensor, Grove - Buzzer
# Note: Use P9_22(UART2_RXD) as GPIO.
# Connect the Grove Buzzer to UART Grove port of Beaglebone Green.
# Connect the Grove - I2C ADC to I2C Grove port of Beaglebone Green, and then connect the Grove - Temperature Sensor to Grove - I2C ADC.
if __name__ == '__main__':
    while True:
        try:
            # Read temperature values in Celsius from Grove Temperature Sensor
            temperature = read_temperature('v1.2')
            # When the temperature reached predetermined value, buzzer is ringing.
            print "temperature = ", temperature
        except IOError:
            print "Error"

post.py

Python
try postin using rest
import requests
import json
import time

ts = int(time.time())

headers = {'Content-Type': 'application/json','Authorization':'Bearer 5ab083f9631e48729423bc0a6978eaa5'}
url = 'https://api.artik.cloud/v1.1/messages'

data = {
  'sdid': '385261a597fd4e808562fde4a87dee3f',
  'type': 'message',
  'ts': '1475160627',
  'data': {'TEMPERATURE':36}
}
params = {}

response = requests.post(url, params=params, data=json.dumps(data), headers=headers)
print "enviado"
print response.status_code
print response.text

send-temp.py

Python
Send the temperature value to Artik Cloud
import time
import math
import grove_i2c_adc
import Adafruit_BBIO.GPIO as GPIO


BUZZER = "P9_22"            # GPIO P9_22
GPIO.setup(BUZZER, GPIO.OUT)
THRESHOLD_TEMPERATURE = 28
adc = grove_i2c_adc.I2cAdc()
def read_temperature(model = 'v1.2'):
    "Read temperature values in Celsius from Grove Temperature Sensor"
    # each of the sensor revisions use different thermistors, each with their own B value constant
    if model == 'v1.2':
        bValue = 4250  # sensor v1.2 uses thermistor ??? (assuming NCP18WF104F03RC until SeeedStudio clarifies)
    elif model == 'v1.1':
        bValue = 4250  # sensor v1.1 uses thermistor NCP18WF104F03RC
    else:
        bValue = 3975  # sensor v1.0 uses thermistor TTC3A103*39H
    total_value = 0
    for index in range(20):
        sensor_value = adc.read_adc()
        total_value += sensor_value
        time.sleep(0.05)
    average_value = float(total_value / 20)
    # Transform the ADC data into the data of Arduino platform.
    sensor_value_tmp = (float)(average_value / 4095 * 2.95 * 2 / 3.3 * 1023)
    resistance = (float)(1023 - sensor_value_tmp) * 10000 / sensor_value_tmp
    temperature = round((float)(1 / (math.log(resistance / 10000) / bValue + 1 / 298.15) - 273.15), 2)
    return temperature
 
if __name__ == '__main__':
 
    while True:
        try:
            # Read temperature values in Celsius from Grove Temperature Sensor
            temperature = read_temperature('v1.2')
            # When the temperature reached predetermined value, buzzer is ringing.
            print "temperature = ", temperature
            import requests
            import json
            import time
            
            ts = int(time.time())
            print "time = ",ts

            headers = {'Content-Type': 'application/json','Authorization':'Bearer 0122adc59504416aabd19af802912339'}
            url = 'https://api.artik.cloud/v1.1/messages'
            
            data = {
              'sdid': '385261a597fd4e808562fde4a87dee3f',
              'type': 'message',
              'ts': ts,
              'data': {'TEMPERATURE':temperature}
            }
            params = {}
            
            response = requests.post(url, params=params, data=json.dumps(data), headers=headers)
            print "enviado"
            print response.status_code

            time.sleep(1)
 
        except IOError:
            print "Error"

Credits

Laurence Daxes

Laurence Daxes

19 projects • 36 followers
Systems Engineer Bachellor, I Love technology, and IoT World https://youtube.com/c/DaxesHacks

Comments