Get GrovePi + sensor value with Raspberry Pi and store it in kintone

Overview

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.

Preparing Raspberry Pi and Grove Pi +

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. sensor04A.png 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

Add kintone app

Create a kintone app from scratch and create a form

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

kin-py-01.png

Set API token on the setting screen of the application

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.

Program development

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()

result

The sensor values measured by Raspberry Pi could be stored in kintone as shown below. kin-py-02.png

I tried to display the following graph with kintone. kin-py-03.png It would be convenient to be able to store data in kintone!

reference

__ 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

Get GrovePi + sensor value with Raspberry Pi and store it in kintone
Get temperature and humidity with DHT11 and Raspberry Pi
[Raspberry Pi] Store the timestamp in the Firebase Realtime Database when the motion sensor detects it.
Check! Get sensor data via Bluetooth with Raspberry Pi ~ Preparation
Make a thermometer with Raspberry Pi and make it viewable with a browser Part 4
Periodically log the value of Omron environment sensor with Raspberry Pi
Pet monitoring with Rekognition and Raspberry pi
Get BITCOIN LTP information with Raspberry PI
Improved motion sensor made with Raspberry Pi
Use PIR motion sensor with raspberry Pi
Inkbird IBS-TH1 value logged with Raspberry Pi
RabbitMQ message notification app in Python with Growl ~ with Raspberry Pi and Julius ~
Logging the value of Omron environment sensor with Raspberry Pi (USB type)
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
I tweeted the illuminance of the room with Raspberry Pi, Arduino and optical sensor
MQTT RC car with Arduino and Raspberry Pi
Get CPU information of Raspberry Pi with Python
[For beginners] I made a motion sensor with Raspberry Pi and notified LINE!
Raspberry + am2302 Measure temperature and humidity with temperature and humidity sensor
Draw a weakness graph in Python and save it in various formats (Raspberry Pi, macOS)
Edit and debug the code in the Raspberry Pi with VS Code's SSH connection feature
Realize a super IoT house by acquiring sensor data in the house with Raspberry Pi
Use kintone API SDK for Python on Raspberry Pi (easily store data in kintone from Raspberry Pi)
Create a color sensor using a Raspberry Pi and a camera
Using the digital illuminance sensor TSL2561 with Raspberry Pi
Easy IoT to start with Raspberry Pi and MESH
Detect mask wearing status with OpenCV and Raspberry Pi
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Measure temperature and humidity with Raspberry Pi3 and visualize with Ambient
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
Get mail from Gmail and label it with Python3
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Getting Started with Yocto Project with Raspberry Pi 4 and WSL2
Troubleshoot with installing OpenCV on Raspberry Pi and capturing
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Make an autonomous driving robot car with Raspberry Pi3 B + and ultrasonic distance sensor HC-SR04
Recursively get the Excel list in a specific folder with python and write it to Excel.
It was great to edit the Python file in the Raspberry Pi with Atom's remote function
I automatically collected my Qiita post data with Raspberry Pi and notified it regularly with Slack
Easy introduction to home hack with Raspberry Pi and discord.py
Create a web surveillance camera with Raspberry Pi and OpenCV
Python beginner opens and closes interlocking camera with Raspberry Pi
Create an LCD (16x2) game with Raspberry Pi and Python
I tried connecting Raspberry Pi and conect + with Web API
Production of temperature control system with Raspberry Pi and ESP32 (1)
I tried using the DS18B20 temperature sensor with Raspberry Pi
Measure and compare temperature with Raspberry Pi and automatically generate graph
Install CaboCha in Ubuntu environment and call it with Python.
Get the weather using the API and let the Raspberry Pi speak!
Get weather information using Yahoo! Open Local Platform (YOLP) and let Raspberry Pi talk with AquesTalkPi
Home hack to buy automatically when it gets cheaper with Amazon Dash Button and Raspberry Pi
Measure temperature, humidity, etc. with SensorTag and send it to Ambient via Raspberry Pi 3 to graph it Part 2
Mutter plants with Raspberry Pi
Getting Started with Heroku-Viewing Hello World in Python Django with Raspberry PI 3
Log in to Raspberry PI with ssh without password (key authentication)
Make a simple CO2 incubator using Raspberry PI and CO2 sensor (MH-Z14A)
Christmas classic (?) Lighting a Christmas tree with Raspberry Pi and Philips Hue
Make a Kanji display compass with Raspberry Pi and Sense Hat
Graph display of household power consumption with 3GPI and Raspberry Pi
Tensorflow with Raspberry Pi. If you stumble with pip, solve it with virtualenv!