I decided to use Raspberry Pi, Grove Pi + starter kit, and kintone in the hackathon, and created a sample program to upload the sensor value of Grove Pi + starter kit to kintone.
The environment of Raspberry Pi used the following that was set before. __ Using Grove Pi + Starter Kit and Camera on Raspberry Pi Initial Settings __ https://qiita.com/yukataoka/items/9df2c74f7cd514e04b97
The sensors in the Grove Pi + starter kit used this time are temperature and humidity, light, and sound. This was also constructed with reference to the following that was tested before. __Grove Pi + Starter Kit Sensor 5.Example Project: Sensor Twitter Feed __ https://qiita.com/yukataoka/items/ef73eb1a329f18015aab#5example-project-sensor-twitter-feed%E3%82%BB%E3%83%B3%E3%82%B5%E5%80%A4%E3%81%AE%E3%83%84%E3%82%A4%E3%83%BC%E3%83%88
Set the fields as follows:
Field name | type | Feed coat / element ID |
---|---|---|
Date and time | Date and time | datetime |
Optical sensor | Numerical value (2 decimal places) | light |
Sound sensor | Numerical value (2 decimal places) | sound |
Temperature sensor | Numerical value (2 decimal places) | temp |
Humidity sensor | Numerical value (2 decimal places) | humidity |
From the application setting screen, the API token setting screen opens in the order of Settings-> Customize / Service Linkage API Token. When you press the "Generate" button, the API token will be added, so check only "Add" and "Save" the access right.
Using the kintone API SDK for Python, we implemented to add the sensor measurement value of Grove Pi + to the kintone record.
See below for acquisition of Grove Pi + sensor measurements. __Grove Pi + Starter Kit Sensor 5.Example Project: Sensor Twitter Feed __ https://qiita.com/yukataoka/items/ef73eb1a329f18015aab#5example-project-sensor-twitter-feed%E3%82%BB%E3%83%B3%E3%82%B5%E5%80%A4%E3%81%AE%E3%83%84%E3%82%A4%E3%83%BC%E3%83%88
See below for the kintone API SDK for Python. __ Use kintone API SDK for Python on Raspberry Pi (easily store data in kintone from Raspberry Pi) __ https://qiita.com/yukataoka/items/9025e1b9951feb419fac
wifi_kintone.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import codecs
import math
import sys
import time
# Grove Pi+
import grovepi
# kintone API SDK for Python
import pykintone
from pykintone import model
import pykintone.structure_field as sf
# Grove Pi+ Connections
sound_sensor = 0 # port A0
light_sensor = 1 # port A1
temperature_sensor = 2 # port D2
# Connect to kintone
subdomein = "kintone subdomain"
appId = "kintone application ID"
token = "kintone API token"
app = pykintone.app(subdomein, appId, token)
# kintone record layout
class recordLayout(model.kintoneModel):
def __init__(self):
super(recordLayout, self).__init__()
self.datetime = ""
self.light = 0.0
self.sound = 0.0
self.temp = 0.0
self.humidity = 0.0
# example code
if __name__=="__main__":
grovepi.pinMode(led,"OUTPUT")
grovepi.analogWrite(led,255) #turn led to max to show readiness
while True:
try:
# Get value from light sensor
light_intensity = grovepi.analogRead(light_sensor)
# Get sound level
sound_level = grovepi.analogRead(sound_sensor)
time.sleep(0.5)
# Get value from temperature sensor
[t,h]=[0,0]
[t,h] = grovepi.dht(temperature_sensor,0)
print ("Temp: %d C, Humidity: %d, Light: %d, Sound: %d" %(t,h,light_intensity/10,sound_level))
# kintone POST
record = recordLayout()
record.datetime = time.strftime('%Y-%m-%dT%H:%M:%S+09:00')
record.light = light_intensity/10
record.sound = sound_level
record.temp = t
record.humidity = h
res = app.create(record)
if res.ok:
print("kintone record add id=" + str(res.record_id) + " revision=" + str(res.revision))
else:
print(res.error.id.encode('utf-8'))
print(res.error.message.encode('utf-8'))
print(res.error.code)
time.sleep(60 * 10)
except KeyboardInterrupt:
exit()
except (IOError,TypeError) as e:
print("Error")
print(e)
exit()
The sensor values measured by Raspberry Pi could be stored in kintone as shown below.
I tried to display the following graph with kintone. It would be convenient to be able to store data in kintone!
__ Using Grove Pi + Starter Kit and Camera on Raspberry Pi Initial Settings __ https://qiita.com/yukataoka/items/9df2c74f7cd514e04b97 __Grove Pi + Starter Kit Sensors Try __ https://qiita.com/yukataoka/items/ef73eb1a329f18015aab __ Use kintone API SDK for Python on Raspberry Pi (easily store data in kintone from Raspberry Pi) __ https://qiita.com/yukataoka/items/9025e1b9951feb419fac
Recommended Posts