Last active
August 29, 2015 14:21
-
-
Save imakin/862b677f47957a7db801 to your computer and use it in GitHub Desktop.
Agus Raspi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-- pip install pyserial | |
#-- pip install PyMySQL | |
from serial import Serial #-- untuk serial | |
import pymysql.cursors #-- MySQL | |
import time #-- delay | |
DBHOST = "192.168.1.52" | |
DATABASE_NAME = "raspberrypi" | |
DATABASE_USERNAME = "root" | |
DATABASE_PASSWORD = "password" | |
# konek ke laptop | |
connection = pymysql.connect(host=DBHOST, user=DATABASE_USERNAME, passwd=DATABASE_PASSWORD, db=DATABASE_NAME, cursorclass=pymysql.cursors.DictCursor) | |
#-- serial dari arduino | |
arduinoserial = Serial("/dev/ttyACM0",9600,timeout=1) | |
while (1): | |
data = arduinoserial.readline() | |
with connection.cursor as cursor: | |
sql = "INSERT INTO settings (value_string) VALUES ('" +data+ "')" | |
cursor.execute(sql) #-- tambah ke database | |
#-- simpan perubahan(penambahan) ke database | |
connection.commit() | |
time.sleep(1) #-- delay 1 detik di tiap loopnya |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment