Hello everybody,
i need a little bit help.
I know it is not the best idea to connect a ESP/Arduino to a SQL Database but i need this to reduce the complexity of my project.
There are better and faster Solutions like this: https://www.b4x.com/android/forum/threads/rdc-based-on-mqtt.72416/#content
I used the library in the Link below, to connect an ESP8266 to an mySQL/MariaDB Database.
Link: https://github.com/ChuckBell/MySQL_Connector_Arduino
This works perfektly.
This is the terminal output:
Connecting MariaDB...
Connected to server version 5.5.5-10.1.23-MariaDB-9+deb9u1
id,gain,gain_start,gain_faktor,intervall,wert,akku,rssi
1,1.89,15.00,6.00,32,3.64,3.22,-70
The fields in my MariaDB Database Tabel are:
CREATE TABLE `haussteuerung_db`.`Sensoren_Wetter` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`sensor_name` varchar(45) NOT NULL DEFAULT '',
`ip` varchar(15) NOT NULL DEFAULT '',
`gruppe` varchar(45) NOT NULL DEFAULT '',
`table_messwerte` varchar(45) NOT NULL DEFAULT '',
`gain` varchar(10) NOT NULL DEFAULT '',
`gain_start` varchar(10) NOT NULL DEFAULT '',
`gain_faktor` varchar(10) NOT NULL DEFAULT '',
`intervall` varchar(10) NOT NULL DEFAULT '',
`wert` varchar(10) NOT NULL DEFAULT '',
`akku` varchar(8) NOT NULL DEFAULT '',
`rssi` varchar(8) NOT NULL DEFAULT '',
`datum` date NOT NULL DEFAULT '0000-00-00',
`zeit` time NOT NULL DEFAULT '00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
B4R Code:
But the value transferrd from Inline C to a global variable is not working or im not able to translate the Bytes.
See here the terminal output:
Output Länge: 400
Output : l��?��?��?��?\��?���?���?��?��?��?w��?��!@���?��!@"@���?4S@S����? |@��L@���?�H@`��?U�U�3;@0��?�?@|�!@��?G�!@���?�#@|@,��?(��?�Q@@���?� @0����Q @
���h @`���?0N @def~�0���?���?���?`��?k400ai @`��?
��?�Q @@x @���@x @P��?0N @P��?]��?<N @
Output : 1073669400
Output 0: 108
Output 1: 252
Output 2: 254
Output 3: 63
Output 4: 132
Output 5: 1
Output 6: 255
Output 7: 63
Output 8: 148
Output 9: 1
Output 10: 255
I don´t get it.
Please help me
I would like to set a global array with doubles like this:
Or a string with the values separated by "," or something like else.
Or is it possible to get the whole "MySQL_Cursor *cur_mem" to a globale variable and work with them?
THX
Chris
EDIT:
I believe my Database table is not the best solution, so if you know a more professional structure i can change the table.
Or if it is nessesary to get a solution for my first question i change the table.
THX
i need a little bit help.
I know it is not the best idea to connect a ESP/Arduino to a SQL Database but i need this to reduce the complexity of my project.
There are better and faster Solutions like this: https://www.b4x.com/android/forum/threads/rdc-based-on-mqtt.72416/#content
I used the library in the Link below, to connect an ESP8266 to an mySQL/MariaDB Database.
Link: https://github.com/ChuckBell/MySQL_Connector_Arduino
This works perfektly.
This is the terminal output:
Connecting MariaDB...
Connected to server version 5.5.5-10.1.23-MariaDB-9+deb9u1
id,gain,gain_start,gain_faktor,intervall,wert,akku,rssi
1,1.89,15.00,6.00,32,3.64,3.22,-70
The fields in my MariaDB Database Tabel are:
CREATE TABLE `haussteuerung_db`.`Sensoren_Wetter` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`sensor_name` varchar(45) NOT NULL DEFAULT '',
`ip` varchar(15) NOT NULL DEFAULT '',
`gruppe` varchar(45) NOT NULL DEFAULT '',
`table_messwerte` varchar(45) NOT NULL DEFAULT '',
`gain` varchar(10) NOT NULL DEFAULT '',
`gain_start` varchar(10) NOT NULL DEFAULT '',
`gain_faktor` varchar(10) NOT NULL DEFAULT '',
`intervall` varchar(10) NOT NULL DEFAULT '',
`wert` varchar(10) NOT NULL DEFAULT '',
`akku` varchar(8) NOT NULL DEFAULT '',
`rssi` varchar(8) NOT NULL DEFAULT '',
`datum` date NOT NULL DEFAULT '0000-00-00',
`zeit` time NOT NULL DEFAULT '00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
B4R Code:
B4X:
Sub Process_Globals
Private Output() As Byte
End Sub
Sub SQL_Select
RunNative("Select", Null)
Dim bc As ByteConverter
Dim str As String = Output
Log("Output Länge: ", Output.Length)
Log("Output : ", Output)
Log("Output : ", str)
' Log("Output 0: ", bc.StringFromBytes(Output))
Log("Output 0: ", Output(0))
Log("Output 1: ", Output(1))
Log("Output 2: ", Output(2))
Log("Output 3: ", Output(3))
Log("Output 4: ", Output(4))
Log("Output 5: ", Output(5))
Log("Output 6: ", Output(6))
Log("Output 7: ", Output(7))
Log("Output 8: ", Output(8))
Log("Output 9: ", Output(9))
Log("Output 10: ", Output(10))
End Sub
#if C
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
//MarieDB Settings
IPAddress server_addr(192, 168, 0, 150); // IP of the MySQL *server* here
char user[] = "myUser"; // MySQL user login username
char password[] = "myPassword"; // MySQL user login password
WiFiClient client;
MySQL_Connection conn((Client *)&client);
// Create an instance of the cursor passing in the connection
MySQL_Cursor cur = MySQL_Cursor(&conn);
void Select(B4R::Object* o) {
char querySelect[] = "SELECT id, gain, gain_start, gain_faktor, intervall, wert, akku, rssi FROM haussteuerung_db.Sensoren_Wetter WHERE id = %d";
char query[128];
delay(1000);
Serial.println("Connecting MariaDB...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
}
else
Serial.println("Connection failed.");
delay(1000);
//Create new Cursor
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
// Execute the query
sprintf(query, querySelect, 1);
cur_mem->execute(query);
// Fetch the columns and print them
column_names *cols = cur_mem->get_columns();
for (int f = 0; f < cols->num_fields; f++) {
Serial.print(cols->fields[f]->name);
if (f < cols->num_fields-1) {
Serial.print(',');
}
}
Serial.println();
//Read the rows and print them
row_values *row = NULL;
char* output[100];
do {
row = cur_mem->get_next_row();
if (row != NULL) {
for (int f = 0; f < cols->num_fields; f++) {
Serial.print(row->values[f]);
output[f] = row->values[f];
if (f < cols->num_fields-1) {
Serial.print(',');
}
}
Serial.println();
}
} while (row != NULL);
// Copy the result
b4r_mariadb::_output->data = output;
b4r_mariadb::_output->length = sizeof(output);
//Deleting the cursor also frees up memory used
delete cur_mem;
}
#End If
But the value transferrd from Inline C to a global variable is not working or im not able to translate the Bytes.
See here the terminal output:
Output Länge: 400
Output : l��?��?��?��?\��?���?���?��?��?��?w��?��!@���?��!@"@���?4S@S����? |@��L@���?�H@`��?U�U�3;@0��?�?@|�!@��?G�!@���?�#@|@,��?(��?�Q@@���?� @0����Q @
���h @`���?0N @def~�0���?���?���?`��?k400ai @`��?
��?�Q @@x @���@x @P��?0N @P��?]��?<N @
Output : 1073669400
Output 0: 108
Output 1: 252
Output 2: 254
Output 3: 63
Output 4: 132
Output 5: 1
Output 6: 255
Output 7: 63
Output 8: 148
Output 9: 1
Output 10: 255
I don´t get it.
Please help me
I would like to set a global array with doubles like this:
B4X:
Public SQL_SensorTemperatur() As Double = Array As Double(0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00) 'Wetter Sensor draussen
Or a string with the values separated by "," or something like else.
Or is it possible to get the whole "MySQL_Cursor *cur_mem" to a globale variable and work with them?
THX
Chris
EDIT:
I believe my Database table is not the best solution, so if you know a more professional structure i can change the table.
Or if it is nessesary to get a solution for my first question i change the table.
THX
Last edited: