Announcement

Collapse
No announcement yet.

Record a device in mysql DB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • alphatech
    replied
    It is an old post but it may work for what I'm trying to do. Unfortunately I do not understand what id the device name he is referencing to, when I put with quotes "Test" it writes test in the database. I'm actually trying to use this script to insert into mysql values from a device. This script is closer than what I was looking for. Any help would be great.

    Leave a comment:


  • joedee983
    replied
    read mysql data and create device

    Hi,
    I'm trying to do something similar to this.
    I would like to create 32 virtual devices (temperature sensors)
    then read the mysql data and put it in the device value.
    I already have the database with the data updated every 5 minutes.
    Then I could use JON00's ploting app.

    The problem is I have no idea where to start, I am not a programmer

    Do you have a script that could get me going in the right direction?

    Thanks

    Leave a comment:


  • mulderonline
    started a topic Record a device in mysql DB

    Record a device in mysql DB

    Hi
    A little code to put a device valuer in a mysql database.
    You have to:
    install mysql (http://www.mysql.fr/)
    create database and account (phpmyadmin)
    create table:
    PHP Code:
    CREATE TABLE `Mesure` (
      `
    Mesure_pkIdbigint(10NOT NULL AUTO_INCREMENT,
      `
    Mesure_Datedatetime DEFAULT NULL,
      `
    Mesure_Idint(11) DEFAULT NULL,
      `
    Mesure_Namevarchar(45) DEFAULT NULL,
      `
    Mesure_Valeurint(11) DEFAULT NULL,
      `
    Mesure_Stringvarchar(100) DEFAULT NULL,
      `
    Mesure_Statusvarchar(45) DEFAULT NULL,
      `
    Mesure_Flagvarchar(45) DEFAULT NULL,
      
    PRIMARY KEY (`Mesure_pkId`)
    ENGINE=InnoDB AUTO_INCREMENT=DEFAULT CHARSET=utf8
    change in the script conn.ConnectionString = "server=YOURIP; user id=YOURDBLOGIN; password=YOURPASSWORD; database=YOURDATABASENAME" with your
    and call this vbscript with an event using name of your device as parameter
    PHP Code:
    'Imports System.Data
    Imports MySql.Data.MySqlClient

    Sub Main(Optional ByVal device As string="0")

    Dim Debug=0

    '
    ===============================================

    Dim conn As MySqlConnection
    Dim myCommand 
    As New MySqlCommand

    ''Données device 
    Dim Mesure_Name
    device
    Dim  Mesure_Id
    =hs.GetDeviceRefByName(Mesure_Name)
    Dim  Mesure_Date hs.DeviceLastChangeRef(Mesure_id)
    Dim Mesure_Valeur hs.DeviceValueEx(Mesure_Id)
    Dim Mesure_String hs.DeviceString(Mesure_Id)
    Dim  Mesure_Statushs.IsOn(Mesure_Id)
    Dim   Mesure_Flag=""
    conn = New MySqlConnection()
    conn.ConnectionString "server=YOURIP; user id=YOURDBLOGIN; password=YOURPASSWORD; database=YOURDATABASENAME"
    myCommand.CommandText "Insert into Mesure VALUES (null, now(),'" Mesure_Id "','" Mesure_Name "','" Mesure_Valeur "','" Mesure_Valeur "','" Mesure_Status "','" Mesure_Flag "')" 
     
    if Debug>0 then
         hs
    .writelog ("mySQL"myCommand.CommandText)
        
    end if   

    myCommand.Connection conn

    Try
         
    conn.Open()
        If 
    Debug>0 then
            hs
    .writelog ("mySQL""Connection Opened Successfully!")
            
    end if
         
    myCommand.ExecuteNonQuery()
        If 
    Debug>0 then
            hs
    .writelog ("mySQL""Logged to database: OK " )
            
    end if
     
    conn.Close()
        Catch 
    myerror As MySqlException
        hs
    .writelog ("mySQL""Error Connecting to Database: " myerror.Message)
    End Try

    End Sub 
Working...
X