У меня очень простой проект Arduino, с которым я борюсь.
Я хотел бы обновить запись в MySQL, используя Arduino с экраном Ethernet. Я использую WAMP для сервера MySQL. В конечном счете, я бы хотел опубликовать показания температуры на сервере mysql каждые 5 минут, но на данный момент это не моя проблема. Я не ветеран с Arduino или MySQL, поэтому я думал, что id спросит Pro.Очень простой Arduino Update SQL Entry
WAMP IP-адрес: 192.168.0.89
Arduino IP-адрес: 192.168.0.177
для MySQL базы данных. Имя пользователя
База данных: "корень"
Database Password: "" Имя
Базы данных: "WordPress"
Таблицы базы данных: "чтение"
Таблица Поле для обновления: "напряжение1"
Запрос:
"UPDATE readings SET voltage1='12v' WHERE device_id=T1;"
На платформе Arduino Эскиз: (получен от: https://launchpad.net/mysql-arduino)
#include "SPI.h"
#include "Ethernet.h"
#include "sha1.h"
#include "mysql.h"
byte mac_addr[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x69, 0xAC };
byte ip_addr[] = { 192, 168, 0, 177 };
byte dns_addr[] = { 192, 168, 0, 37 };
byte gateway_addr[] = { 192, 168, 0, 37 };
byte netmask[] = { 255, 255, 255, 0 };
IPAddress server_addr(192, 168, 0, 89);
Connector my_conn; // The Connector/Arduino reference
char user[] = "root";
char password[] = ""; //the credentials are correct in my code
char INSERT_SQL[] = "UPDATE readings SET voltage1='99' WHERE device_id=T1;";
void setup() {
Serial.begin(115200);
Ethernet.begin(mac_addr, ip_addr, dns_addr, gateway_addr, netmask); //Yes, I know this is way more than necessary, but just to play it safe
delay(1000);
Serial.print("IP: ");
Serial.println(Ethernet.localIP()); // debugging
Serial.println("Connecting...");
if (my_conn.mysql_connect(server_addr, 3306, user, password)) //connect to database
{
delay(500);
my_conn.cmd_query(INSERT_SQL); //Possible problem here, i want to update not insert.
Serial.println("Query Success!");
}
else
Serial.println("Connection failed.");
}
void loop() {
}
Serial Monitor:
IP: 192.168.0.177
Connecting...
Он никогда не соединиться.
Возможный дубликат [Arduino to connection connection] (http://stackoverflow.com/questions/30241550/arduino-to-database-connection) –
Я не понимаю, почему мы беспокоимся об обновленной части, когда вы еще не могу подключиться ... –