ESP8266 a Mysql

Help tengo un problema estoy manejando el ESP8266 que es un modulo wifi, en este modulo estoy leyendo consultas de una base de datos en MySQL al igual en este programa le envio una distancia mediante un ultrasonico a Mysql, al enviar distancia no tengo problema alguno. Mi problema es que quiero guardar en una variable el resultado de una consulta
Aqui mi pograma

#include <ESP8266WiFi.h>           // Use this for WiFi instead of Ethernet.h
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

int trig = 2;
int echo = 4;
long tiempo = 0;
float distancia = 0;
int umbral = 0;
String y;
char query3[128];
char x=2;
char query1[] = "SELECT `PRActual` FROM pr1.programacion WHERE Prensa='%d';";

IPAddress server_addr(10,10,10,180);  // IP of the MySQL *server* here
char user[] = "progra";              // MySQL user login username
char password[] = "sunfallfestival64";        // MySQL user login password

WiFiClient client;                 // Use this for WiFi instead of EthernetClient
MySQL_Connection conn(&client);
MySQL_Cursor* cursor;

// WiFi card example
char ssid[] = "TransNav2";         // your SSID
char pass[] = "06TNMjunio";     // your SSID Password

void iniciarTarjetaRed(){
{
 
 Serial.begin(115200);
 while (!Serial); // wait for serial port to connect. Needed for Leonardo only

 // Begin WiFi section
 Serial.printf("\nConnecting to %s", ssid);
 WiFi.begin(ssid, pass);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }

 // print out info about the connection:
 Serial.println("\nConnected to network");
 Serial.print("My IP address is: ");
 Serial.println(WiFi.localIP());

 Serial.print("Connecting to SQL...  ");
 if (conn.connect(server_addr, 3306, user, password))
   Serial.println("OK.");
 else
   Serial.println("FAILED.");
 
 // create MySQL cursor object
 cursor = new MySQL_Cursor(&conn);
}
}

void llamarpr()
{
 sprintf(query3,query1,x);
 MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
 // Execute the query
 cur_mem->execute(query3);
 // 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;
 do {
   row = cur_mem->get_next_row();
   if (row != NULL) {
     for (int f = 0; f < cols->num_fields; f++) {
       Serial.print(row->values[f]);
       if (f < cols->num_fields-1) {
         Serial.print(", ");
       }
     }
     Serial.println();
   }
 } while (row != NULL);
 // Deleting the cursor also frees up memory used
 delete cur_mem;
}

void llamarcabiadades()
{
 char query2[] = "SELECT `cavidades` FROM pr1.prs WHERE PR='%c';";  
 char letritas[128];
 sprintf(letritas,query2,query1);
 MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
 // Execute the query
 cur_mem->execute(letritas);
 // 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;
 do {
   row = cur_mem->get_next_row();
   if (row != NULL) {
     for (int f = 0; f < cols->num_fields; f++) {
       Serial.print(row->values[f]);
       if (f < cols->num_fields-1) {
         Serial.print(", ");
       }
     }
     Serial.println();
   }
 } while (row != NULL);
 // Deleting the cursor also frees up memory used
 delete cur_mem;
}

void grabarDatoBD(int pdato){
 if (conn.connect (server_addr,3306, user, password)){
   char INSERT_SQL[] = "UPDATE `pr1`.`programacion` SET `Piezasc`='%d' WHERE `Prensa`=2";
   char query[128];
   sprintf(query,INSERT_SQL, pdato);
   MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);  
   cur_mem->execute(query);
   delete cur_mem;
   conn.close();
   Serial.println("Registro Grabado");
 }
 else 
 {
   Serial.println("Conecion a la BD MySQL ha fallado.");
 }
}
void setup() {
 // put your setup code here, to run once:

 pinMode(trig, OUTPUT);
 pinMode(echo, INPUT);
 Serial.begin(115200);
 iniciarTarjetaRed();
 llamarpr();
 llamarcabiadades();
}

void loop() {
  //put your main code here, to run repeatedly|||||||||||:
 digitalWrite(trig, HIGH);
 delayMicroseconds(10);
 digitalWrite(trig, LOW);
 tiempo = pulseIn(echo, HIGH);
 distancia = tiempo / 59;
 Serial.println("DISTANCIA = " + String(distancia) + "cm");
 grabarDatoBD(distancia);  
 delay(20000);

}

en la imagen marque lo que me lee mi consulta que es el CP0869F ese valor lo quiero guardar en una variable para despues utilizarlo para pedir las cavidades en mi programa

1ro doble post http://forum.arduino.cc/index.php?topic=555726.0
2. Mal posteado y te envié por el primero como editarlo.
Al menos corregiste el título porque antes era Novato en Apuros.

  1. Código sin etiquetas
  2. Imagen que no se ve.

Te postee las normas del foro y como editar todo y no se si lo leíste. Supongo que no. Te envío privado para que hagas las correcciones que te estoy señalando y el otro hilo será borrado.