我正在使用此代码
#include <ESP8266WiFi.h>
const char* ssid = "UnderSpeed";
const char* password = "q1w2e3r4t5__";
const char* host = "192.168.1.185"; //it will tell you the IP once it starts up
//just write it here afterwards and upload
int r0 = D0;
int r1 = D1;
int r2 = D2;
int r3 = D3;
int btn0 = D5;
WiFiServer server(301); //just pick any port number you like
void setup() {
Serial.begin(115200);
delay(10);
Serial.println(WiFi.localIP());
// prepare GPIO2
pinMode(r0, OUTPUT);
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(btn0, INPUT_PULLUP);
digitalWrite(r0, HIGH);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
while (!client.available()) {
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
client.flush();
// Match the request
if (req.indexOf("") != -10) { //checks if you're on the main page
if (req.indexOf("/r0-OFF") != -1) { //checks if you clicked OFF
digitalWrite(r0, HIGH);
Serial.println("Relay-0 OFF");
}
if (req.indexOf("/r0-ON") != -1) { //checks if you clicked ON
digitalWrite(r0, LOW);
Serial.println("Relay-0 ON");
}
if (req.indexOf("/r1-OFF") != -1) { //checks if you clicked OFF
digitalWrite(r1, HIGH);
Serial.println("Relay-1 OFF");
}
if (req.indexOf("/r1-ON") != -1) { //checks if you clicked ON
digitalWrite(r1, LOW);
Serial.println("Relay-1 ON");
}
if (req.indexOf("/r2-OFF") != -1) { //checks if you clicked OFF
digitalWrite(r2, HIGH);
Serial.println("Relay-2 OFF");
}
if (req.indexOf("/r2-ON") != -1) { //checks if you clicked ON
digitalWrite(r2, LOW);
Serial.println("Relay-2 ON");
}
if (req.indexOf("/r3-OFF") != -1) { //checks if you clicked OFF
digitalWrite(r3, HIGH);
Serial.println("Relay-3 OFF");
}
if (req.indexOf("/r3-ON") != -1) { //checks if you clicked ON
digitalWrite(r3, LOW);
Serial.println("Relay-3 ON");
}
if (req.indexOf("/btn0") != -1) { //checks if you clicked OFF
buton_islemi();
}
}
else {
Serial.println("invalid request");
client.stop();
return;
}
// Prepare the response
String s = "HTTP/1.1 200 OK\r\n";
s += "Content-Type: text/html\r\n\r\n";
s += "<!DOCTYPE HTML>\r\n<html>\r\n";
s += "<br><input type=\"button\" name=\"rly0-on\" value=\"Relay-0 ON \" onclick=\"location.href='/r0-ON'\">";
s += "<br>";
s += "<br><input type=\"button\" name=\"rly0-off\" value=\"Relay-0 OFF\" onclick=\"location.href='/r0-OFF'\">";
s += "<br><br><br>";
s += "<br><input type=\"button\" name=\"rly1-on\" value=\"Relay-1 ON \" onclick=\"location.href='/r1-ON'\">";
s += "<br>";
s += "<br><input type=\"button\" name=\"rly1-off\" value=\"Relay-1 OFF\" onclick=\"location.href='/r1-OFF'\">";
s += "<br><br><br>";
s += "<br><input type=\"button\" name=\"rly2-on\" value=\"Relay-2 ON \" onclick=\"location.href='/r2-ON'\">";
s += "<br>";
s += "<br><input type=\"button\" name=\"rly2-off\" value=\"Relay-2 OFF\" onclick=\"location.href='/r2-OFF'\">";
s += "<br><br><br>";
s += "<br><input type=\"button\" name=\"rly3-on\" value=\"Relay-3 ON \" onclick=\"location.href='/r3-ON'\">";
s += "<br>";
s += "<br><input type=\"button\" name=\"rly3-off\" value=\"Relay-3 OFF\" onclick=\"location.href='/r3-OFF'\">";
s += "<br><br><br>";
s += "<br><input type=\"button\" name=\"btn0\" value=\"Button-0 \" onclick=\"location.href='/btn0'\">";
s += "<br>";
s += "</html>\n";
client.flush();
// Send the response to the client
client.print(s);
delay(1);
}
void buton_islemi() {
digitalWrite(r0, !digitalRead(r0));
delay(500);
digitalWrite(r1, !digitalRead(r1));
delay(500);
digitalWrite(r2, !digitalRead(r2));
delay(500);
digitalWrite(r3, !digitalRead(r3));
Serial.println("Button Pressed");
}
假设将Datagridview导出到word,但未显示列标题。大多数情况下,我在此行中遇到异常错误
Dim ht2 As Table
For i As Integer = 0 To _RowCount2 - 2
For _col As Integer = 0 To _ColCount2 - 1
Dim colType As Type = Form2.DataGridView2.Columns(_col).GetType
If colType.Name = "DataGridViewImageColumn" Then
Dim _image As Image = DirectCast(Form2.DataGridView2.Rows(i).Cells(_col).FormattedValue, Image)
Clipboard.SetImage(_image)
ht2.Cell(i + 1, _col + 1).Range.Paste()
Else
ht2.Cell(i + 1, _col + 1).Range.Text = Form2.DataGridView2.Rows(i).Cells(_col).Value.ToString()
End If
Next
Next