Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Send data to MySQL Database via Virtual Device


lukashwm

Question

Hello folks,

 

I found this tutorial: 

Please login or register to see this link.

 , it also contains a link to this forum but the link itself is dead. I want to know if this is still possible because I can't get it to work. 

 

I can put the string in my url bar and it works. Like: http://myServer/data_post.php?type=temperature_sensor&name=exampleDevice&value=10.0&id=900 . It creates something in the database. So the webserver seems to run.

In HC2 device Overview the virtual device also confirms the button action by showing "Weather uploaded" but nothing happens.

 

The only difference is I got a webserver not a NAS to work as the database bridge. Also put the following inside the .htaccess file of the fibarostats folder to make sure its not a CORS policy problem.

 

<IfModule mod_headers.c>
  Header add Access-Control-Allow-Origin "http://myIpAdress" 
  Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
  Header add Access-Control-Allow-Headers: "Content-Type"
  Header add Access-Control-Allow-Credentials true 

  RewriteEngine on
  RewriteBase /
</IfModule>

 

kind regards,

Lukas

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Maybe my solution help you:

Please login or register to see this link.

 , but in result of forum search engine  you will find many others solution to send any data to sql server. Second forum with many example is freach forum:

Please login or register to see this link.

 

 

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • I tried to implement ur solution but can't get it working...

     

    How do I have to implement the lua scripts ? I create a Virtual Device or a scene with a button and insert the lua code right? But if I click a button or run the scene than nothing happens. No errors, just nothing. Is there a way to debug? Or am I just missing something?

     

    ATM i got two different domains and I am able to fire http request and they are also inserted to my database but I got no chance to do it from the HC2. 

    Link to comment
    Share on other sites

    • 0

    sql-syslog.lua is the scene (look the header), if you need write any message to sql (in this example like syslog message) call this scene from any other scene or VD by commands:

    if __fibaroSceneId~=nil then dev = 'S' .. __fibaroSceneId else dev = 'V' .. fibaro:getSelfId() end

    fibaro:startScene(76, {{sev = "info"}, {src = dev}, {msg = "test"}}) fibaro:startScene(76, {{sev = "info"}, {src = dev}, {msg = urlencode("test")}})

     

    or

    fibaro:startScene(76, {{sev = "debug"}, {src= "any info 1"}, {msg = "any info 2"}})

     

    when 76 is scene id with sql-syslog.lua code, and src, msg, sev is data for sql table.

    All was described in source.

     

    I tested and used this scripts many time.

     

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...