BeagleBone Green Temperature Monitor on Artik Cloud

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

Categories: Intermediate

It’s a simple project for send data from BBG to Artik Cloud, in my opinion Artik Cloud is very promising, but their website is very unstable (and slow), and I had some problems and errors (as you will see at the end of the project).

Reading temperature VIA I2C ADC

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" 


Create a new device (on Artik Cloud)

Test Publishing Data

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 


Publish temperature in real time

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" 


See Data Log

time for coding all together

Publishing from BBG

Messages Log

For How use Postman, see my previous Project:

https://www.hackster.io/LaurenceHR/consuming-artik-cloud-api-from-postman-chrome-extension-8f6dfb?ref=user&ref_id=43908&offset=1

On Artik Cloud

What's wrong with you, Artik?

For an inexplicable reason, Artik doesn’t show my data sent in the charts :/

Comments are not currently available for this post.