Inviare dati da Arduino ad una pagina web asp.net 4 / C#

Finalmente oggi ci sono riuscito!
Sono riuscito ad inviare dati da arduino ad una pagina web da me creata.

Vediamo come

Pagina web:
acquire.aspx.cs

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class acquire : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text = Request.QueryString["username"];
        TextBox2.Text = Request.QueryString["password"];
        TextBox3.Text = Request.QueryString["datastream"];
        TextBox4.Text = Request.QueryString["value"]; 
    }
}

 

Frontend:
acquire.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="acquire.aspx.cs" Inherits="acquire" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>

 

Arduino Sketch:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 
  192,168,2,20 };
byte server[] = { 
  46,16,168,17 }; 

Client client(server, 80);

void setup() { 
  Ethernet.begin(mac, ip); 
  Serial.begin(9600);
}

void loop()
{
  delay(1000);
  Serial.println("connecting...");
  client.connect();
  if (client.connected()) {
    Serial.println("connected");
    client.println("GET http://antrea.7hostfree.com/acquire.aspx?username=USERFROMARDUINO&password=PASSFROMARDUINO&datastream=DATASTREAMFROMARDUINO&value=VALUEFROMARDUINO HTTP/1.1");
    client.println ( "Host: http://antrea.7hostfree.com" ) ;  
    client.println();
  } 
  else {
    Serial.println("connection failed");
  }
  if (client.available()) {
    do {
      char c = client.read();
      Serial.print(c);
    }
    while (client.available());
  }
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
}

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Anti-Spam Quiz: