Unable to save arduino log data (light sensor) to phpmyadmin

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);
	}

image

Sample of manually enter in url, it work fine and able to save to database
localhost/garden/components/insertbright?brightness=36
Appreciate

I don't think you need this ampersand:

    cliente.print("&brightness=");

before that I had tried it, this is the second solution i tried

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.