Arduino_Scuola
Published © GPL3+

Send messages to the Arduino Yun with your internet browser

Create a web page containing a form that let you send text messages to your Arduino Yun thanks to the WebServer feature of the Yun.

IntermediateFull instructions provided45 minutes5,782
Send messages to the Arduino Yun with your internet browser

Things used in this project

Story

Read more

Code

Code snippet #2

Arduino
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

YunServer server;
String msg;


void setup () {
  
  Serial.begin(9600);
  Bridge.begin();
  server.listenOnLocalhost();
  server.begin();  
  
  
}
 
void loop () {
  //*********Read new message from the client**************
  YunClient client = server.accept(); //check new clients
  
  if(client) {
    String command = client.readStringUntil('/');  //read the incoming data 
    if (command == "msg") {      
       msg = client.readStringUntil('/');             // read the incoming data
    }
    client.stop();   
  }  
  
}

Code snippet #1

Arduino
<!DOCTYPE HTML>
<head>
<title>Yun Messages</title>
<script type="text/javascript" src="zepto.min.js"></script>	
</head>
<body>
<H1> Insert your message </H1> 
<form name="msgform" onSubmit="return sendMsg()">
<input type="text" name="msg">
<input type="submit" value="Yun it!" >
</form>
<script type="text/javascript">	
	
function sendMsg() {	
$.get('/arduino/msg/' + document.msgform.msg.value + '/',
	function(){
		alert("Success");
	}
);
return false;

}
</script>
</body>

Credits

Arduino_Scuola

Arduino_Scuola

32 projects • 155 followers

Comments