单片机怎样把采集的数据上传到网站的数据库中

单片机怎样把采集的数据上传到网站的数据库中,第1张

1、直接:单片机配以太网接口,移植个tcp/ip协议站,单片机直接登陆服务器上传数据

2、间接:单片机通过串口、USB等其他接口把数据传给有以太网的模块或设备(如电脑),在传到服务器。

把传感器的采集的数据传入数据库,可以通过C#编程和ZIGBEE技术来实现啊,可以用visual stdio 2008或2010把串口程序写好,然后把用IAR 写好的软件下到目标板中就是ZigBee开发板,

程序中需要添加连接到数据库的函数,先建好数据库以及你要采集的信息数据的一个综合的表格,就是数据库中表格的各项列值,这个列的名称和串口程序里的值是一致的,附上代码表示

using System.Data.SqlClient

public partial class Form1 : Form

    {

        string ConStr

        SqlConnection conn

        public Form1()

        {

            InitializeComponent()

        }

private void button1_Click(object sender, EventArgs e)

        {

            ConStr = "server=.database=StudendIntegrated Security=SSPI"

            conn = new SqlConnection(ConStr)

conn.Open()

            string name = textBox1.Text

            name = "'" + name + "'"

            string passwd = textBox2.Text

try

            {

                SqlCommand sqlcom = new SqlCommand("insert into luo(name,password) values(" + name + " ," + passwd + ")", conn)

                sqlcom.ExecuteNonQuery()

                MessageBox.Show("连接成功!", "!")

            } catch (Exception a)

            {

                MessageBox.Show("未添加!","!")

            }

}

private void Form1_Load(object sender, EventArgs e)

        {

           

            ConStr = "server=.database=StudendIntegrated Security=SSPI"

            conn = new SqlConnection(ConStr)

conn.Open()

if (conn.State == ConnectionState.Open)

            {

                label5.Text = "连接成功并打开数据库"

                //conn.Close()

            }

        }

private void button3_Click(object sender, EventArgs e)

        {

            ConStr = "server=.database=StudendIntegrated Security=SSPI"

            conn = new SqlConnection(ConStr)

conn.Open()

if (conn.State == ConnectionState.Open)

            {

                label5.Text = "连接成功并打开数据库"

                //conn.Close()

            }

          

           

        }

private void button2_Click(object sender, EventArgs e)

        {

ConStr = "server=.database=StudendIntegrated Security=SSPI"

            conn = new SqlConnection(ConStr)

            string name2 = textBox3.Text

                name2 = "'" + name2 + "'"

            conn.Open()

           

            try

            {

               

                SqlCommand sqlcom = new SqlCommand("delete from luo where name=" + name2, conn)

                int a=sqlcom.ExecuteNonQuery()

                if (a <=0)

                {MessageBox.Show("删除失败!","!")

                }

                else MessageBox.Show("删除成功!", "!")

                conn.Close()

            }

            catch (Exception a)

            {

               

                MessageBox.Show("未删除!","!")

            }

           

        }

有两种方法,一种是:采集器可以连接数据库,采集数据后建立一个数据库连接,然后进行数据插入;另一种是:数据采集器将数据上发到数据库所在的服务器缓存,在服务器上有解析服务,将数据进行解析,然后传入数据库


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10016295.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-04
下一篇2023-05-04

发表评论

登录后才能评论

评论列表(0条)

    保存