저는 최근에 내 Arduino에서 센서 데이터를 기존 MySQL 데이터베이스에 쓰기 위해 Arduino Uno Wifi을 구입했습니다. 나는 기존의 라이브러리들 (예 : this과 같은)이 이더넷이나 wifi 방패의 도움으로 정확히 동일한 일을하기 때문에 큰 문제는 아닌 것으로 생각했다. 내가 Uno Wifi를 구입 한 직후에 발견 한 문제는 모두 Ethernet.h 또는 Wifi.h와 같은 자체 라이브러리를 필요로한다는 것입니다. 나는 이미 와이파이 (Wi-Fi) 준비가되어있는 Arduino를 구입했기 때문에 제 의견으로는별로 의미가없는 것들을 사용하기 위해 추가 방패가 필요할 것입니다. 지원되는 ThingSpeak과 같은 것이 있지만 내 데이터베이스의 유연성을 잃어 버리고 싶지 않고 ThingSpeak에서 제공하는 모든 추가 분석 서비스가 필요하지는 않습니다.Arduno Uno Wifi를 사용하여 SQL 데이터베이스에 쓸 수 있습니까?
나의 아주 근사한 질문은 - 내 (새로운) Arduino Uno WIFI를 사용하여 간단한 INSERT INTO 문으로 기존 데이터베이스에 데이터를 쓰는 방법이 있습니까?
편집: 그게 내가 지금까지 함께했다 내가 오늘 몇 가지를 시도
의 :이 서버와 바로 연결을 설정할 수없는 프로그램 결과
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <UnoWiFiDevEd.h>
IPAddress server_addr(88, 198, 61, 231); // IP of the MySQL *server* here
char user[] = "USERxxxxxx"; // MySQL user login username
char password[] = "xxxxxxxxx"; // MySQL user login password
// Sample query
char INSERT_SQL[] = "INSERT INTO `arduino_test`(`Humidity`, `Temperature`, `DateTime`) VALUES (60, 23, '2017-02-02 20:34:20')";
WiFiClient client;
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(9600);
while (!Serial); // wait for serial port to connect
Wifi.begin();
Serial.println("Connecting");
if (conn.connect(server_addr, 3306, user, password)) {
delay(5000);
Serial.println("Connection successful");
} else {
Serial.println("Connection failed!");
}
}
void loop() {
delay(2000);
Serial.println("Recording data.");
// Initiate the query class instance
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
// Execute the query
cur_mem->execute(INSERT_SQL);
// Note: since there are no results, we do not need to read any data
// Deleting the cursor also frees up memory used
delete cur_mem;
}
직렬 모니터에 "연결 중"을 계속 인쇄하십시오.
편집 2 : 뭔가를 알아 낸
, @cagdas 아이디어 덕분에 먼저 연결을 확인합니다. 와 "응답 : 10709"연결이 "200 주"을 인쇄해야 작동하는 경우
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <Wire.h>
#include <UnoWiFiDevEd.h>
IPAddress server_addr(88, 198, 61, 231); // IP of the MySQL *server* here
char user[] = "USERxxxxxx"; // MySQL user login username
char password[] = "xxxxxxx"; // MySQL user login password
// Sample query
char INSERT_SQL[] = "INSERT INTO `arduino_test`(`Humidity`, `Temperature`, `DateTime`) VALUES (60, 23, '2017-02-02 20:34:20')";
WifiData client;
MySQL_Connection conn((Client *)&client);
void setup() {
char* connector = "rest";
char* server = "download.arduino.org";
char* method = "GET";
String resource = "/latest.txt";
Serial.begin(9600);
Ciao.begin();
pinMode(2, INPUT);
delay(5000);
doRequest(connector, server, resource, method);
Wifi.begin();
Serial.println("Connecting");
if (conn.connect(server_addr, 3306, user, password)) {
Serial.println("Connection successful");
} else {
Serial.println("Connection failed!");
}
}
void loop() {
delay(2000);
Serial.println("Recording data.");
// Initiate the query class instance
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
// Execute the query
cur_mem->execute(INSERT_SQL);
// Note: since there are no results, we do not need to read any data
// Deleting the cursor also frees up memory used
delete cur_mem;
}
void doRequest(char* conn, char* server, String command, char* method) {
CiaoData data = Ciao.write(conn, server, command, method);
if (!data.isEmpty()) {
Ciao.println("State: " + String (data.get(1)));
Ciao.println("Response: " + String (data.get(2)));
Serial.println("State: " + String (data.get(1)));
Serial.println("Response: " + String (data.get(2)));
}
else {
Ciao.println ("Write Error");
Serial.println ("Write Error");
}
}
: 이 지금 내 스케치입니다. 내 루프를 제거하고 그냥 잘 작동 (하지만 분명히 데이터베이스에 아무것도 기록하지 않습니다)
void loop() {}
작성하는 경우 그러나 실제로는 그냥 0을 출력한다. 루프에서 코드를이 if 문에 넣으면 "if (conn.connect (server_addr, 3306, user, password))"문구도 올바른 결과를 반환하지 않습니다. 이 시점에서 나는이 코드가 작동하지 않는 이유에 대해 여전히 단서가 없지만 가능한 해결책에 대한 더 깊은 통찰력을 줄 수 있다고 생각합니다. 는 또한 아두 이노 IDE 나에게 당신은 그것을 포함하여 ESP8266의 과부하 WiFiClient를 사용할 자격이
The sketch is using 50% of the memory
Global variables use 88% of the memory
There is only little RAM left -> stability issues possible (sorry, it's in german)
대답은 의미가 않습니다
당신은 귀하의 코드에 계속? – cagdas
@cagdas이 이상한 행동이 어디에서 왔는지 알고 있습니까? 아니면 다음에 무엇을 할 생각입니까? –
Wi-Fi 인증 정보는 어디에 있습니까? – cagdas