How do I send data from Arduino to SQL Server

Hello Arduino fans. I’m just working on my ‘big’ project but i can’t do it myself.

Problem : I want to make a sensor, that can measure temperature (using DHT22), measure humidity (in %), upload time from NTC server (time and date), and displaying that info on LCD display (time and date is on top, at bottom left is temperature [in ºC] and at bottom right is humidity). I also want its own IP Address (think its solved, see attachment)and that data will automatically send to server (SQL).

About sending info on SQL server : I want to have a subprogram named “sendinfo” and it will contain code about how to send, where to send, where to write and how to write that info. (the name of SQL server and IP and stuff is no need for now to know). I just can’t figure out how to make it.

guys please if someone can or know how to do it please help me (its important for me).

if u have questions be sure to leave a comment about them and i will try to explain

Update : I’ve solved uploading info on LCD screen

Need to solve :
receiving data from ntc server (try to add it to my original code [just add please don’t edite mine])
how to upload .php files on sql server to receive Data from arduino and write them to my created table (or how to use that .php files).

where i found .php files >> http://www.instructables.com/id/Save-data-of-temperature-and-humidity-on-MySQL-wit/

temperature_and_humidity_sensor_solved.ino (1020 Bytes)

You have posted a program but you have not told us what it actually does and what you want it to do that is different.

Also, for short programs it is easier for many readers if you include the code in your post like this

//FUNKCNE 
/*

*/

#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
#include <Process.h>

Process date;                   // process used to get the date 
int hours, minutes, seconds;    // for the results
int lastSecond = -1;            // need an impossible value for comparison
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip (192, 168, 243, 253);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  Serial.begin(9600); 
  lcd.begin(16, 2);
  lcd.print(" TIME AND DATE");    //max 16 signs  example :  14:56_12.10.2018 --> replaces time and date
  lcd.setCursor(0, 1);            //set cursor on the second line of LCD
  while (!Serial) { 
    ; // wait for serial port to connect. Needed for native USB port only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  
}


void loop() {
  lcd.display();
  
    EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

…R

@Ivo_Creamo_Durec, why have you quoted your own Post?

...R

I’m new here. excuse me
i want it to do it all on its own i don’t do anything just power it on
it will receive data from dht22 and print them on the LCD (solved, see code), then that data will be send to SQL server, but i don’t know how to solve this because i do not know much about sql servers and how they works. that info will be write into table i created (will send prt. sc.). I also found a code .php but i don’t know if i must it write to the query or what so that’s the biggest problem for me now.

temperature_and_humidity_sensor_solved.ino (996 Bytes)

Sorry I can't help with the SQL Server stuff.

You will probably attract the attention of people who do know if you edit your Original Post and change the title to something like "How do I send data from Arduino to SQL Server"

...R

Thanks for tips and help :slight_smile:
I will edit it

how can i add more attachments ???

Ivo_Creamo_Durec:
how can i add more attachments ???

If you use the full editor (you can click Preview to get to it) there is an option at the bottom for adding attachments to a Post.

By the way, if you are adding new material please add it in your next Reply rather than making changes to an earlier Reply. That way the Thread makes sense when read from top to bottom.

…R

ok i updated it and attachment too, i will add more only in replies then. Thanks

btw.: how can i add the code opened like you did upper ??? (and thanks for helping me :slight_smile: )

Ivo_Creamo_Durec:
ok i updated it and attachment too, i will add more only in replies then. Thanks

What have you updated? I don’t normally go back to re-read older Posts.

btw.: how can i add the code opened like you did upper ??? (and thanks for helping me :slight_smile: )

Use the code button </> or put [code]  [/code] around your code

…R

To retrieve date and time from NTP server : this topic

I don't think you'll find an Arduino connector to MSSQL Server.
You must make a request to an HTTP server that will make the job : those topic. Replace the path by yours :
GET /update.php?temperature=xx&humidity=yy HTTP/1.1
Host: your.host.name

thanks xartefact i will look on it

yesterday i found another problem :frowning: : i've created menu and i want that default setup on screen (when you will power up arduino Uno) it will show date and time and at the bottom temp. and humidity. when you will press SELECT button on the lcd button shield, it will open menu and then you can go up and down and in subprograms. My problem is that when i press select i will go to menu but when i want to go down in it, it will return me to default setup (and its a lil' bit bugged). please help me i think my conditions are wrong but i dont know where.

(i want to put code and /code but it was too long)

One problem is, your arduino act like a server :

you defined role of a server ... but i'm not sure if you can send POST request or html request to the ms sql server as server ...

EthernetServer server(80);

I should try :

EthernetClient client;