Hello . I will describe what it is about . I want to make with the 8266 power temp and humidity sensors in different rooms with writing to a database
I have a QNAP TS 251+ running mySQL , with a database created , user - dedicated only to this database
database : house ; user : domtemp , pass : same (I hit) also tests without password effect same .
Esp8266 programmed with C ( code of the example on which I learn below ) . Unfortunately ...
With the network connects without problems , but with the base no longer .
At first I thought that I knocked something in the database itself .... but from python the connection to the database works without problems .
Where did I make a mistake ..... Can he help me ?
.
I have a QNAP TS 251+ running mySQL , with a database created , user - dedicated only to this database
database : house ; user : domtemp , pass : same (I hit) also tests without password effect same .
Esp8266 programmed with C ( code of the example on which I learn below ) . Unfortunately ...
With the network connects without problems , but with the base no longer .
At first I thought that I knocked something in the database itself .... but from python the connection to the database works without problems .
Where did I make a mistake ..... Can he help me ?
#include <DHT.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#define DHTPIN D6 // what digital pin we're connected to. If you are not using NodeMCU change D6 to real pin
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
char ssid[] = "siec"; // Network Name
char pass[] = "haslo"; // Network Password
WiFiServer server(80);
IPAddress ip(192, 168, 1, 29);
IPAddress gateway(192, 168, 1,1);
IPAddress subnet(255, 255, 255, 0);
WiFiClient client;
MySQL_Connection conn((Client *)&client);
char INSERT_SQL[] = "INSERT INTO dom.dom_temp( temperatura , wilgotnosc) VALUES (NULL, NULL)";
char query[128];
IPAddress server_addr(192,168,1,31); // MySQL server IP
char user[] = "domtemp"; // MySQL user
char password[] = "domtemp"; // MySQL password
void setup() {
Serial.begin(9600);
Serial.println("Initialising connection");
Serial.print(F("Setting static ip to : "));
Serial.println(ip);
Serial.println("");
Serial.println("");
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi Connected");
WiFi.macAddress(mac);
Serial.println("");
Serial.print("Assigned IP: ");
Serial.print(WiFi.localIP());
Serial.println("");
Serial.println("Connecting to database");
// na tej pętli się zawiesza ..... nie łączy... drukuje same kropki
while (conn.connect(server_addr, 3306, user , password) != true) {
delay(200);
Serial.print ( "." );
}
Serial.println("");
Serial.println("Connected to SQL Server!");
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
delay(10000); //10 sec
sprintf(query, INSERT_SQL, temperature , humidity );
// sprintf(query, INSERT_SQL, soil_hum, t);
Serial.println("Recording data.");
Serial.println(query);
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(query);
delete cur_mem;
}