Question

I have already completed the controlling of devices through internet using buttons. I used Arduino Uno+ SD CARD+ Ethernet shield. Now I want to modify it so that used can send text commands through form submission to control the same.

I could do it when I was using the Arduino Uno Memory for HTML code but now facing problems when I am using SD Card for HTML. Expecting the code module for the same.

Was it helpful?

Solution

Yes, it's possible. But you'll need to use a web socket. I've done that using PHP. So, you'll create a page with html and php that, when you click on the submit button, will send the commands. It must be like that, in php:

<?php 
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

socket_connect($sock,"ip number of arduino", 8080);

$messsage = '0';
if (isset($_POST['on'])){
    $msg='1';
}
if (isset($_POST['off'])){
    $msg='0';
}

socket_write($sock, $msg);
?>

So you just need to write a html to send the post method when a form be submited.

OTHER TIPS

Submission of HTML form actually invokes POST or GET method of HTTP protocol. This protocol is human readable.

Example of HTTP request from w3schools :

POST /test/demo_form.asp HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2

This is what you'll get into arduino buffer. You can simply search for name1= pattern and read the value and act accordingly.

In the example below I read values of variables s and e.

word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) {
  bfill = ether.tcpOffset();
  char* socket = strstr((char *)Ethernet::buffer + pos, "?s=");


  if(socket != 0){
    byte s = getIntArg(socket, "s");
    byte e = getIntArg(socket, "e");
    Serial.println("Request");
    Serial.println(s);
    Serial.println(e);
    PlanActions(s, e)
    }

Form for this request looks like:

<form action="." method="POST">
    <select name="s" size="1">
        <option value="0">TV</option>
        <option value="1">HiFi</option>
    </select>
    <input name="e" type="submit" value="0">
    <input name="e" type="submit" value="1">
</form>

In the example I'm sending simple form page from arduino, but you can have the page wherever you want. It can be on local computer or web server. Just change action to something like <form action="arduino-ip"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top