Hello all, I need some help or ideas for my webserver task. I just want to light on a led with a webserver running on the linux side of Yun. The client is going to be just a simple button which toggles a led. I will communicate linux side with Arduino using bridge.put() and bridge.get().
This is my Arduino code:
#include <Bridge.h>
char* t={(0)};
int aux=0;
void setup() {
pinMode(13,OUTPUT);
digitalWrite(13, HIGH);
delay(60000);
Bridge.begin();
digitalWrite(13, LOW);
}
void loop() {
aux=Bridge.get("on",t,1);
if(t[1]==1) digitalWrite(13,HIGH);
}
I've succesfully made a small webserver (shows date and time) running on Yun using bottle framework and html with javascript.
Here's the bottle code:
#!/usr/bin/python
import sys
from bottle import run, route, template
sys.path.insert(0, '/usr/lib/python2.7/bridge/')
from bridgeclient import BridgeClient as bridgeclient
bc = bridgeclient()
index_html = open('hola_mundo.html').read()
@route('/home')
def indice():
return template(index_html)
if __name__ == '__main__':
run(host='192.168.50.13', port=5555, debug=True)
Here's HTML/Javascript code
<!DOCTYPE html>
<html>
<body>
<h1>My first Javascript app</h1>
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>
</body>
</html>
I don't know how can I get Javascript talk to Bottle and use bridglient.put() to send command to Arduino, if someone could guide me I'd be very grateful.