我想将传感器数据(如DHT)从NODEMCU发送到LABVIEW。 有没有图书馆或草图来做这个? NODEMCU以站点模式连接到网络。 在labview中,我必须使用哪个库来执行此操作?
答案 0 :(得分:0)
解决: 1.在Arduino IDE中试用这个库:ESP8266WiFi.h
主机是您的PC,如192.168.1.11
端口:550(例如)
#include <ESP8266WiFi.h>
const char* ssid = "xxxx"; // SSID
const char* password = "xxxx"; // Password
const char* host = "xxx.xxx.xxx.xxx"; // Server IP
const int port = 550; // Server Port
const int watchdog = 5000; // Watchdog frequency
unsigned long previousMillis = millis();
void setup() {
Serial.begin(115200);
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");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
unsigned long currentMillis = millis();
if ( currentMillis - previousMillis > watchdog ) {
previousMillis = currentMillis;
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}
String url = "/watchdog?command=watchdog&uptime=";
url += String(millis());
url += "&ip=";
url += WiFi.localIP().toString();
// Envoi la requete au serveur - This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
}
}
2。 labview:你需要2个街区才能做到这一点:
TCP LISTEN
TCP READ