This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Edit script but it still run old script
#1
I use a script 1/1/2 to update script of address 1/1/1 example from log(1) to log(2) using those commands:

Code:
        db:update('scripting', {script = nScript}, {id = s.id})
        script.disable(s.name)
      script.enable(s.name)
        script.reload()

The update is successful (I see the line log(2) in 1/1/1) but when I change the value of 1/1/1, it still run old script (show 1 in log instead of 2)
How can I fix this? Thank you
Reply
#2
Could someone help me please?
Reply
#3
Explain your use case. You should not need to update scripts dynamically.
Reply
#4
(17.03.2025, 09:25)admin Wrote: Explain your use case. You should not need to update scripts dynamically.

I want my end-user can update the script without any coding skill. Like they can setup a script that turn on Light 1, wait 8 second then turn off Light 2, and they can edit it later when they need. They can do that with only tap/swipe item on visulization and the code will change depend on their action.
Reply
#5
Why not use scenes for this?
Reply
#6
(17.03.2025, 09:36)admin Wrote: Why not use scenes for this?

Because I think write/read script is faster and more complex than edit/read scene. And sometime I need to check value of a specific address before taking the action. Example, if 1/1/1 = 10 and 1/1/2 = true I will do action A but when 1/1/1 = 10 and 1/1/2 = false I will do action B.
Reply
#7
Your client will use objects to insert the values so why do you need to modify the script?
------------------------------
Ctrl+F5
Reply
#8
(17.03.2025, 09:42)Daniel Wrote: Your client will use objects to insert the values so why do you need to modify the script?

It's not just about control the device. Example I creat some text Input in the Vis. And maybe they can add the option send email to "abc@gmail.com" with the subject "Something happen" which they can set themself when the object is set to specific value.
Reply
#9
String, number - no difference. You still must use a object where your user will type the values and your script will just read this.
------------------------------
Ctrl+F5
Reply
#10
(17.03.2025, 09:50)Daniel Wrote: String, number - no difference. You still must use a object where your user will type the values and your script will just read this.

Let say when they want to send the email to 100 user, if I use object or storage to store that value, it's not a wise idea. My Idea is I can use only one object.
Example
The script I want to edit is 1/0/1
1/7/1 will store the email address

When 1/0/1 = 1, they want to send email to "abc", they will set 1/7/1 to "abc", 1/0/1 will be set to 'email("abc")'
then they want to send to another email "abcd"  , they will set 1/7/1 to "abcd" , 1/0/1 will be set to 'email("abc") email(abcd)'
...
Reply
#11
Use this:
Code:
scriptid = 23
scriptcode = [[
log('1234')
]]

params = {
  data = {
    id = scriptid,
    scriptonly = true,
  },
  script = scriptcode
}

webrequest = require('webrequest')
res, err = webrequest('scripting', 'save', params)
Reply
#12
(17.03.2025, 10:20)admin Wrote: Use this:
Code:
scriptid = 23
scriptcode = [[
log('1234')
]]

params = {
  data = {
    id = scriptid,
    scriptonly = true,
  },
  script = scriptcode
}

webrequest = require('webrequest')
res, err = webrequest('scripting', 'save', params)

Sadly it didnt work. I also try to run your whole code alone but it the script which has ID = 23 didnt change to log('1234')
Reply
#13
Anything in the error log? Which firmware version do you have?
Reply
#14
The log said: module 'webrequest' not found:. How can I install it?

I'm using 20210521 FWW
Reply
#15
Install 2024 firmware: https://openrb.com/firmwares/
Reply
#16
(17.03.2025, 13:27)admin Wrote: Install 2024 firmware: https://openrb.com/firmwares/

Is there any alternate way to do it with http request? I dig a bit and see that I can send http post to "/scada-main/scripting/save" with the payload contain data and script ID. But I dont know how to extractly do that in code. I try some code but get the response (404 Not Found)
Reply


Forum Jump: