2017-02-01 8 views
2

저는 최근에 내 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)

+0

대답은 의미가 않습니다

당신은 귀하의 코드에 계속? – cagdas

+0

@cagdas이 이상한 행동이 어디에서 왔는지 알고 있습니까? 아니면 다음에 무엇을 할 생각입니까? –

+0

Wi-Fi 인증 정보는 어디에 있습니까? – cagdas

답변

1

같은 것을 알려줍니다.

#include <ESP8266WiFi.h> 
#include <MySQL_Connection.h> 
#include <MySQL_Cursor.h> 

WiFiClient client; 
MySQL_Connection conn((Client *)&client); 

네트워크 클라이언트가 너무 WiFiClient는 당신이 필요로하는 물건을 구현해야, 아두 이노 측에서 저녁 식사 유산이있다.

WiFi.begin(SSID,PASS); 
+0

안녕하세요, cagdas, 답장을 보내 주셔서 감사합니다. 나는 그것을 시도하고 불행히도 그것은 정말로 나를 위해 일하지 않는다. ESP8266WiFi.h에서 "/Arduino/libraries/ESP8266WiFi/src/ESP8266WiFiType.h:26:19 : 치명적인 오류 : queue.h : 해당 파일이나 디렉토리가 없습니다." #include "예외가 발생합니다. –