I would like to control a LED connected to raspberry pi using Alexa and java. I have successfully achieved it following your tutorial https://www.hackster.io/nishit-patel/controlling-raspberry-pi-using-alexa-33715b. Now I would like to have access and modify mysql database and that required a java code. So I am trying to convert this following python code to java. Any idea, please?
Thanks in advance.
import logging
import os
import MySQLdb
from flaskext.mysql import MySQL
from flask import Flask, render_template
from flask_ask import Ask, request, session, question, statement
import RPi.GPIO as GPIO
db=MySQLdb.connect(host='xxx.xxx.xxx.x',user='xxxx',passwd='xxxxxx',db='xxxxx')
cursor=db.cursor()
app = Flask(name)
ask = Ask(app, "/")
logging.getLogger('flask_ask').setLevel(logging.DEBUG)
STATUSON = ['on','high']
STATUSOFF = ['off','low']
@ask.launch
def launch():
speech_text = 'Welcome to Raspberry Pi Automation.'
return question(speech_text).reprompt(speech_text).simple_card(speech_text)
@ask.intent('GPIOControlIntent', mapping = {'status':'status'})
def Gpio_Intent(status,room):
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.OUT)
if status in STATUSON:
GPIO.output(17,GPIO.HIGH)
cursor.execute("INSERT INTO led (Etat) VALUES ('1')")
db.commit()
return statement('turning {} lights'.format(status))
elif status in STATUSOFF:
GPIO.output(17,GPIO.LOW)
cursor.execute("INSERT INTO led
(Etat
) VALUES ('0')")
db.commit()
return statement('turning {} lights'.format(status))
else:
return statement('Sorry not possible.')
@ask.intent('AMAZON.HelpIntent')
def help():
speech_text = 'You can say hello to me!'
return question(speech_text).reprompt(speech_text).simple_card('HelloWorld', speech_text)
@ask.session_ended
def session_ended():
return "{}", 200
if name == 'main':
if 'ASK_VERIFY_REQUESTS' in os.environ:
verify = str(os.environ.get('ASK_VERIFY_REQUESTS', '')).lower()
if verify == 'false':
app.config['ASK_VERIFY_REQUESTS'] = False
app.run(debug=True)