Hi guys, I encountered problem which is my logged data can send successful to my server, but my db doesn't receive the data. It work fine for DHT22 only, other sensors also unable to work. I am using Xampp and ci3 framework. As below is my code
#include <SPI.h>
#include <Ethernet.h>
const int light_analog = A0;
int light_Value = 0;
byte mac[] = { my MAC here };
byte ip[] = {client ip here }; //Enter the IP of ethernet shield
byte serv[] = {server ip} ; //Enter the IPv4 address
EthernetClient cliente;
void setup() {
Serial.begin(9600); //setting the baud rate at 9600
Ethernet.begin(mac, ip);
}
void loop() {
test();
delay(15000);
}
void test() {
light_Value = analogRead(light_analog);
int percent_light = map(light_Value, 1023, 0, 0, 100);
if (cliente.connect(serv, 80)) { //Connecting at the IP address and port we saved before
Serial.println("brightness-connected");
cliente.print("GET /garden/Components/insertbright?"); //Connecting and Sending values to database
cliente.print("&brightness=");
cliente.print(percent_light);
//Printing the values on the serial monitor
Serial.print("bright= ");
Serial.println(percent_light);
cliente.stop(); //Closing the connection
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
CI3 php code
Model
public function brightness_insert($brightness_array)
{
$query = $this->db->insert('light_sensor', $brightness_array);
return $query;
Controller
public function insertbright()
{
$brightness_array = array(
'brightness' => $this->input->get('brightness'),
);
$this->Component_model->brightness_insert($brightness_array);
}
Sample of manually enter in url, it work fine and able to save to database
localhost/garden/components/insertbright?brightness=36
Appreciate