Hello there,
I'm trying to get a line of text from mysql database created in phpmyadmin and display it in serial monitor. It needs to get updated as the database updates and the latest one should be displayed. Below is the code for arduino as well as php code to get the text.
code for arduino:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 10, 101 };
byte gw[] = {192, 168, 10, 1 };
byte subnet[] = { 255, 255, 255, 0 };
IPAddress server(192, 168, 10, 100 );
EthernetClient client;
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true;
void setup() {
Ethernet.begin(mac, ip, gw, subnet);
Serial.begin(9600);
}
void loop() {
Serial.print(" Connecting to server Database ");
if (client.connect(server, 80)) {
client.println("connection ok");
Serial.println("connection ok");
client.print("GET /msm.php HTTP/1.1");
Serial.print("GET /msm.php HTTP/1.1");
client.println("Host: localhost");
Serial.println("Host: localhost");
client.println("User-Agent: Arduino");
Serial.println("User-Agent: Arduino");
client.println("Accept: text/html");
Serial.println("Accept: text/html");
while (client.available())
{
Serial.print(client.read());
}
client.println("Connection: close");
Serial.println("Connection: close");
client.println();
Serial.println();
client.stop();
}
else {
Serial.println("connection failed");
}
delay(10000);
}
php code to get text, this code is returning a text eg: "this is final one" but its not getting upto serial monitor.
<?php
$conn = mysqli_connect("localhost","root","","testboard");
$result = mysqli_query($conn, "SELECT notice FROM class1 ORDER BY id DESC");
$row = mysqli_fetch_array($result, MYSQLI_NUM);
$request = $row[0];
return $request;
?>
In serial monitor, its printing long combination of numbers instead of what i wanted to print. ie: "this is final one"
Connecting to server Database connection ok
GET /msm.php HTTP/1.1Host: localhost
User-Agent: Arduino
Accept: text/html
72848480474946493252484832669710032821011131171011151161310689711610158327011410544324855327797121325048504932505158525358484932717784131083101114118101114583265112979910410147504652465255324087105110545241327911210111083837647494649464910732807280475546514650561310671111101161011101164576101110103116104583251505413106711111011010199116105111110583299108111115101131067111110116101110116458412111210158321161011201164710411610910859329910497114115101116611051151114556565357454913101310603368796784898069327284777632808566767367323445474773698470474768846832728477763250464847476978346210601041161091086260104101971006210601161051161081016252484832669710032821011131171011151166047116105116108101621060471041019710062609811110012162106010449626697100328210111311710111511660471044962106011262891111171143298114111119115101114321151011101163297321141011131171011151163211610497116321161041051153211510111411810111432991111171081003211011111632117110100101114115116971101004660981143247621060471126210601041146210609710010011410111511562651129799104101475046524652553240871051105452413279112101110838376474946494649107328072804755465146505632831011141181011143297116321081119997108104111115116328011111411632564860479710010011410111511562106047981111001216260471041161091086210Connection: close