Python Forum

Full Version: How to send data from remotely hosted HTML form to Pi
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm working on a small project to turn home lights On & Off using Raspberry Pi. I'm able to do so using Python . Now I want to make a web interface to control things. This is the interface I made initially: https://sajidjunoon.github.io/IoT_Project

I wanted to know how will I send data from remotely hosted app/HTML button to my RaspberryPi. What language/library will be used here and how it will be implemented?

I'm sorry if this question is not meant to be posted to this forum.
(Jun-19-2019, 07:09 PM)sajid Wrote: [ -> ]I wanted to know how will I send data from remotely hosted app/HTML button to my RaspberryPi. What language/library will be used here and how it will be implemented?
You can still use Python eg Flask is fine for this.
So from your html code vaule get send to server Flask.
On server can send to eg PI LAN http://adresse.lan/light_on

Minimal running example.
from flask import Flask, request

app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        light = request.form.getlist('light')[0]
        if light == 'on':
            print('Light on')
            # http://adresse.lan/light_on
        if light == 'off':
            print('Light off')
            # http://adresse.lan/light_off
    return '''\
    <form method="post">
      <input type="checkbox" name="light" value="on" checked>
      <input type="checkbox" name="light" value="off" checked>
      <input type="submit">
    </form>'''

app.run(debug=True)
For host recommendation look this post
Thank you for your reply. I got the solution which I was looking for. It's AWS IoT, I'm doing this using AWS IoT SDK where communication will happen over MQTT in JSON format.