想在arduino IDE post 資料上http. 網站是用asp.net寫的,服務器(IIS)也假設在我電腦上,在arduino ide視窗裡顯示連接成功,但是post請求上去的資料並有沒顯示在http,按F12看後台也沒有找到
arduino代碼
const char* ssid = "xxx";
const char* password = "xxx";
//Your Domain name with URL path or IP address with path
const char* serverName = "http://155.137.158.34:xxx/Login";
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
}
void loop() {
//Send an HTTP POST request every 10 minutes
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(client, serverName);
// Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Data to send with HTTP POST
String httpRequestData = "api_key=tPmAT5Ab3j7F9&sensor=BME280&value1=24.25&value2=49.54&value3=1005.14";
// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
// If you need an HTTP request with a content type: application/json, use the following:
//http.addHeader("Content-Type", "application/json");
//int httpResponseCode = http.POST("{\"api_key\":\"tPmAT5Ab3j7F9\",\"sensor\":\"BME280\",\"value1\":\"24.25\",\"value2\":\"49.54\",\"value3\":\"1005.14\"}");
// If you need an HTTP request with a content type: text/plain
//http.addHeader("Content-Type", "text/plain");
//int httpResponseCode = http.POST("Hello, World!");
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
asp 的aspx代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="_2A_LeeMingChak.Login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body background="image\loginbg.JPEG" style=" background-repeat:no-repeat ;background-size:cover;background-attachment: fixed;">
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="lb_welcome" runat="server" Font-Bold="True" Font-Italic="True" Font-Size="XX-Large" style="z-index: 1; left: 250px; top: 64px; position: absolute; margin-top: 0px" Text="歡迎使用醫療綜合管理系統" BorderStyle="Solid" BackColor="White" BorderWidth="5px"></asp:Label>
<asp:Label ID="lb1" runat="server" BorderStyle="Groove" style="z-index: 1; left: 30px; top: 164px; position: absolute; width: 139px" Text="請選擇使用者身份:" BackColor="White" BorderColor="#3399FF" BorderWidth="5px"></asp:Label>
<asp:RadioButton ID="rb_usertype_a" runat="server" BorderStyle="Ridge" style="z-index: 1; left: 414px; top: 163px; position: absolute; width: 81px;" Text="管理員" GroupName="usertype" OnCheckedChanged="rb_usertype_a_CheckedChanged" BackColor="#FF6600"/>
<asp:Label ID="lb_2" runat="server" BorderStyle="Groove" style="z-index: 1; left: 29px; top: 229px; position: absolute; width: 139px" Text="使用者賬戶:" BackColor="White" BorderColor="#3399FF" BorderWidth="5px"></asp:Label>
<asp:TextBox ID="tb_id" runat="server" BorderStyle="Ridge" style="z-index: 1; left: 194px; top: 228px; position: absolute; width: 200px" BorderColor="Black" BorderWidth="3px"></asp:TextBox>
<asp:Label ID="lb_3" runat="server" BorderStyle="Groove" style="z-index: 1; left: 29px; top: 294px; position: absolute; width: 139px" Text="密碼:" BackColor="White" BorderColor="#3399FF" BorderWidth="5px"></asp:Label>
<asp:Label ID="lb_5" runat="server" BorderStyle="Groove" style="z-index: 1; left: 25px; top: 431px; position: absolute; width: 139px" Text="驗證碼:" BackColor="White" BorderColor="#3399FF" BorderWidth="5px"></asp:Label>
<asp:TextBox ID="tb_yzm" runat="server" BorderStyle="Ridge" style="z-index: 1; left: 195px; top: 432px; position: absolute; width: 100px; " BorderColor="Black" BorderWidth="3px"></asp:TextBox>
<asp:RegularExpressionValidator ID="rev_pw" runat="server" ControlToValidate="tb_pw" ErrorMessage="密碼長度10個以上,至少要有一個0-9的數字,至少要有一個小寫的英文字母(a-z),至少要有一個大寫的英文字母(A-Z)" style="z-index: 1; left: 411px; top: 272px; position: absolute; width: 250px" ValidationExpression="^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$" ForeColor="White"></asp:RegularExpressionValidator>
<asp:Label ID="lb_yzm" runat="server" BorderStyle="Solid" style="z-index: 1; left: 319px; top: 431px; position: absolute; width: 70px" BackColor="White"></asp:Label>
<asp:Label ID="lb_4" runat="server" BorderStyle="Groove" style="z-index: 1; left: 26px; top: 361px; position: absolute; width: 139px; margin-top: 0px;" Text="請再次輸入密碼:" BackColor="White" BorderColor="#3399FF" BorderWidth="5px"></asp:Label>
<asp:TextBox ID="tb_pw2" runat="server" BorderStyle="Ridge" style="z-index: 1; left: 192px; top: 360px; position: absolute; width: 200px" TextMode="Password" BorderColor="Black" BorderWidth="3px"></asp:TextBox>
<asp:Button ID="btn_login" runat="server" BorderStyle="Outset" style="z-index: 1; left: 192px; top: 495px; position: absolute; right: 1191px" Text="登入" OnClick="btn_login_Click" BackColor="White" BorderColor="#FFCCFF" BorderWidth="5px" />
<asp:Button ID="btn_register" runat="server" BorderStyle="Outset" style="z-index: 1; left: 258px; top: 496px; position: absolute" Text="註冊" OnClick="btn_register_Click" BackColor="White" BorderColor="#66FFCC" BorderWidth="5px" />
<asp:Label ID="lb_ts" runat="server" BorderStyle="Inset" style="z-index: 1; left: 355px; top: 489px; position: absolute" BackColor="White" BorderColor="Black" BorderWidth="7px" Font-Size="XX-Large"></asp:Label>
<asp:RequiredFieldValidator ID="rfv_userid" runat="server" ControlToValidate="tb_id" ErrorMessage="You must enter a user ID" style="z-index: 1; left: 433px; top: 231px; position: absolute" ForeColor="White"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="cv_pw" runat="server" ControlToCompare="tb_pw2" ControlToValidate="tb_pw" ErrorMessage="Passwords do not match! Please" style="z-index: 1; left: 427px; top: 364px; position: absolute" ForeColor="White"></asp:CompareValidator>
<asp:TextBox ID="tb_pw" runat="server" BorderColor="Black" BorderStyle="Ridge" BorderWidth="3px" style="z-index: 1; left: 191px; top: 296px; position: absolute; width: 200px" TextMode="Password"></asp:TextBox>
<asp:RadioButton ID="rb_usertype_p" runat="server" BackColor="#FFFF66" BorderStyle="Ridge" GroupName="usertype" OnCheckedChanged="rb_usertype_p_CheckedChanged" style="z-index: 1; left: 200px; top: 162px; position: absolute; width: 60px" Text="市民" />
<asp:RadioButton ID="rb_usertype_mp" runat="server" BackColor="#33CCFF" BorderStyle="Ridge" GroupName="usertype" style="z-index: 1; left: 290px; top: 163px; position: absolute; width: 96px; right: 277px;" Text="醫護人員" OnCheckedChanged="rb_usertype_mp_CheckedChanged" />
</form>
</body>
</html>
我的arduino ide視窗
我的chrome後台
我在IIS設置了request
請問怎麼樣才能把arduino的數據上傳並顯示在我的網站裡