Connect to SQL Server from Microcontroller (Arduino or Fez with .Net Micro Framework)

旧时模样 提交于 2019-12-05 08:55:30

Honestly, I would make a thin service that would sit in-front of your database and use something lightweight like protobuf to get the data into your micro.

I doubt you'll be able to implement TDS in the limited power and memory of an AVR.

Still not sure what your question is about... The tag "arduino" let me think you are asking about Arduino code, but the comment below make me doubt you are asking for .NET stuff. Here's a tentative answer should the question be on how to manage things on the Arduino side.

Method 1: using serial communication and a proxy

On the Arduino, I would simply output SQL queries on the Serial port, like this:

Serial.begin(115200);
Serial.println("INSERT INTO table_name VALUES (value1, value2, value3,...);");

On the server side (or on the side of the computer you are using to access the Internet), I would write a simple script that opens the connection with the DB and forward the query to it. This could be achieved either by CLI commands or opening a network connection on a given port. I do not use Windows/.NET, etc... but on a GNU/Linux box, using python and mysql, the proof-of-concept code that I would write would look something like (BEWARE: UNTESTED!):

import os, serial

self.ser = serial.Serial("/dev/ttyUSB0", 115200)
query = self.ser.readline().strip()
return os.popen("mysql -u<my_usr> -hlocalhost -p<my_pass> -e" + query)

Method 2: using a lan shield or directly an Arduino LAN board

The latter will be shipped sometimes soon (see this presentation if you are curious about it). The first is already available. Writing the code for it should be dead easy (see docs here). The result should be something down the line of (UNTESTED):

Serial.begin(<speed>);
Ethernet.begin(<mac_number>, <ip>);
Client client(<server>, <port>);
client.println("GET <path> HTTP/1.0");
while (client.available()) {
  char c = client.read();
  Serial.print(c);
}

HTH!

I don't know how you got the XML idea, but I advise you to have a look at the Microsoft SQL Server protocol documentation, which gives you a pretty good idea of what you actually would have to implement to natively talk to your SQL server.

Depending on a couple parameters:

1.0 You are connected via serial port to a host PC.

Build a client app on the host pc which received commands over the serial port and translates these commands into sql, using ADO or whatever you prefer.

2.0 You are using an ethernet shield.

In this instance you now have a few options:

2a. Connect to a webservice and use Soap or a similiar http protocol to send commands, which the service will translate into database commands.

2b. Attempt to implement at least a subset of the TDS protocol and directly connect to the sql server and issue commands directly to it.

cyberloco

You can set a HTTP end point in SQL Server and then send HTTP put commands to it.

Mauro Zanin

Look at http://www.logicdata.it/sqleng, they have a nice SQLServer for micros.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!