Go Down

Topic: How do I send data from Arduino to SQL Server (Read 457 times) previous topic - next topic

Ivo_Creamo_Durec

May 22, 2018, 09:25 am Last Edit: May 25, 2018, 07:21 am by Ivo_Creamo_Durec
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/

Robin2

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
Code: [Select]
//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("<br />");
          }
          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
Two or three hours spent thinking and reading documentation solves most programming problems.

Robin2

@Ivo_Creamo_Durec, why have you quoted your own Post?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Ivo_Creamo_Durec

#3
May 24, 2018, 11:17 am Last Edit: Jun 22, 2018, 06:55 am by Ivo_Creamo_Durec
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.

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

Ivo_Creamo_Durec

Thanks for tips and help :)
I will edit it

Ivo_Creamo_Durec

how can i add more attachments ???

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

Ivo_Creamo_Durec

#8
May 25, 2018, 07:23 am Last Edit: May 25, 2018, 07:26 am by Ivo_Creamo_Durec
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 :) )

Robin2

#9
May 25, 2018, 09:06 am Last Edit: May 25, 2018, 09:08 am by Robin2
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.

Quote
btw.: how can i add the code opened like you did upper ??? (and thanks for helping me :) )
Use the code button </> or put [code]  [/code] around your code

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

xartefact

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

Ivo_Creamo_Durec

#11
May 29, 2018, 09:08 am Last Edit: Jun 22, 2018, 06:51 am by Ivo_Creamo_Durec
thanks xartefact i will look on it

yesterday i found another problem :(  : 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)

Go Up