Arduino uno wifi rev2, raspberry and mysql

Hello,

I have Arduino Uno Wifi Rev2 and I'm trying to get temperature sensor to send results to MySQL.
I have followed this tutorial: [Part 1]Temperature sensor DS18b20 with Arduino – PiGreek's Blog

and part 1 went very well. Now I'm in part 2: [Part 2]Temperature sensor DS18b20 with Arduino – MySQL – PiGreek's Blog

It takes temperature but it won't send it anywhere.
I had to change code little bit, tutorial was made for esp8266wifi.

Here is my code:

#include <SPI.h>
#include <WiFiNINA.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include "arduino_secrets.h" 

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the Wifi radio's status
#define ONE_WIRE_BUS 4 // DS18B20 Data Pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);


// MySQL
IPAddress server_addr(192,168,43,219);   // MySQL SERVER
char user[] = "testi"; // MySQL USERNAME
char password[] = "testi123"; // MySQL PASSWORD
char INSERT_DATA[] = "INSERT INTO sensors.room (value, created) VALUES (%s, NOW() + INTERVAL 1 HOUR)";
char query[128];
char temperature[10];

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

void setup() {

    //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < "1.0.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWifiData();

  Serial.begin(115200);
  WiFi.begin(ssid, pass);
  sensors.begin();

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }
  Serial.println ( "" );
  Serial.print ( "Connected to " );
  Serial.println ( ssid );
  Serial.print ( "IP address: " );
  Serial.println ( WiFi.localIP() );
  Serial.println("DB - Connecting...");
  while (conn.connect(server_addr, 3306, user, password) != true) {
    delay(500);
    Serial.print ( "." );
  }
}

void saveTempData() {
            sensors.requestTemperatures();
            MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
            Serial.print("Temp: ");
            Serial.println(sensors.getTempCByIndex(0));
            Serial.print("Query: ");
            dtostrf(sensors.getTempCByIndex(0), 2, 2, temperature);
            sprintf(query, INSERT_DATA, temperature);
            cur_mem->execute(query);
            Serial.println(query);
            delete cur_mem;
            Serial.println("Data stored!");
            delay(2000);
 }

void loop() {
  saveTempData();
    // check the network connection once every 10 seconds:
  delay(10000);
  printCurrentNet();
}

void printWifiData() {
  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.println(ip);

  // print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  printMacAddress(mac);
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);
  Serial.print("BSSID: ");
  printMacAddress(bssid);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type:");
  Serial.println(encryption, HEX);
  Serial.println();
}

void printMacAddress(byte mac[]) {
  for (int i = 5; i >= 0; i--) {
    if (mac[i] < 16) {
      Serial.print("0");
    }
    Serial.print(mac[i], HEX);
    if (i > 0) {
      Serial.print(":");
    }
  }
  Serial.println();
}

and my Arduino board looks like this:

I have installed mysql-database to my Raspberry. Phpmyadmin works well and I created database normally like in tutorial.

I edited code little bit, now in serial monitor, it tries to connect to database but it won't show temperature anymore.

I'm not sure, is this about remote connection to mysql.

There was a similar question yesterday and I eventually remembered this:

By default, MySQL is listening only to local connections (127.0.0.1).

You have to explicitly configure it to accept remote connections.

wildbill:
There was a similar question yesterday and I eventually remembered this:You have to explicitly configure it to accept remote connections.

Hi, thank's for your reply.
I will check remote connection-things soon

How about code?
Is it ok?

Hello,

I installed again mysql and I ran mysql_secure_installation and allowed remote connections and changed bind_address 0.0.0.0.

I can access phpmyadmin from my another device and I can see databases.
It still doesn't connect to my database.

Is code okey, is it about my mysql-settings?

Can you connect from another machine using http or does it insist on https? I doubt that your Arduino library is capable of https.

What do your logs say? Is MySql seeing your connection attempts and rejecting them?

If you're not making progress, I'd be tempted to use WireShark or the like at the server and see how the packet traffic differs between successful and unsuccessful requests to connect.