@jkandasa thanks a lot (again) for that tip. My transmit delay was set, but maybe 100 ms were too low for signing to finish before the next message. Now I set it to 200 ms and it seems to work according to my first tests.
Another minor question: I added Names to my sensors (which were auto-detected during node presentation if that matters), but they get overwritten with for example 74522 TSF:MSG:READ,17-17-0,s=22,c=0,t=23,pt=0,l=0,sg=1:
which seems to be the complete serial incoming message for that sensor. Is this know and is there a way to avoid this name-changing?
Posts made by Anduril
-
RE: set a time delay in java operation
-
set a time delay in java operation
Hey there,
I have a node with multiple sensors and want to update them with a java script. I have signatures activated and us an RFM69 transmitter on my gateway.
1574774 TSF:MSG:READ,0-0-17,s=21,c=3,t=16,pt=0,l=0,sg=0: 1574793 TSF:MSG:SEND,17-17-0-0,s=255,c=3,t=17,pt=6,l=25,sg=0,ft=0,st=OK:<NONCE> 1574814 TSF:MSG:READ,0-0-17,s=21,c=1,t=24,pt=0,l=17,sg=1:10000000000000000 1574888 TSF:MSG:READ,0-0-17,s=22,c=3,t=16,pt=0,l=0,sg=1: 1574907 TSF:MSG:SEND,17-17-0-0,s=255,c=3,t=17,pt=6,l=25,sg=1,ft=0,st=OK:<NONCE> 1574928 TSF:MSG:READ,0-0-17,s=22,c=1,t=24,pt=0,l=17,sg=1:20000000000000000 1574978 TSF:MSG:SEND,17-17-0-0,s=21,c=3,t=16,pt=0,l=0,sg=1,ft=0,st=OK: 1574998 TSF:MSG:READ,0-0-17,s=255,c=3,t=17,pt=6,l=25,sg=1:<NONCE> 1576260 !TSF:MSG:SEND,17-17-0-0,s=21,c=1,t=24,pt=0,l=17,sg=1,ft=0,st=NACK:10000000000000000 1576273 TSF:MSG:READ,0-0-17,s=4,c=3,t=16,pt=0,l=0,sg=1: 1576294 TSF:MSG:SEND,17-17-0-0,s=255,c=3,t=17,pt=6,l=25,sg=1,ft=1,st=OK:<NONCE> 1576315 TSF:MSG:READ,0-0-17,s=4,c=1,t=24,pt=0,l=19,sg=1:Hans 1577578 !TSF:MSG:SEND,17-17-0-0,s=22,c=3,t=16,pt=0,l=0,sg=1,ft=0,st=NACK: 1577584 !TSF:MSG:SIGN FAIL
I think adding something like
Thread.sleep(x)
could solve the problem, as the signature transmission would have a little more time to avoid collission (but maybe I'm wrong). Sending them manually works absolutely fine.mcApi.sensor().sendPayload(S1); mcApi.sensor().sendPayload(S2); mcApi.sensor().sendPayload(ID); mcApi.sensor().sendPayload(Name1); mcApi.sensor().sendPayload(Name2);
Is there any way to insert a kind of delay in a script?
Regards,
Anduril -
RE: possible to read xml file in custom widget?
This feature is great (at least for my usage). Is it also possible to update the values in the xml file? I don't mean adding new nodes or other fancy stuff, only updating for example
/student/details/class
fromThree
toFour
.
As far as I read the xpath is just a pointer in the tree of an xml, so there is no option to manipulate items. Maybe there is another function available to do this. -
assign value on user confirmation (button click)
Hi,
I have succesfully imported a bunch of values out of a xml file to variable repositories. Just to keep the topic simple and readable in future I ask this question in a new thread.
Now I want to have some kind of user confirmation (for example a click on a button) that the data was checked and should be sent to the nodes. I can write a simple script to assign the values from the repositories to the sensor values (by their UUID), but I don't know how to activate that script by butten or other user input.Regards,
Anduril -
RE: possible to read xml file in custom widget?
wow that's great... thanks a lot.
-
RE: possible to read xml file in custom widget?
Thanks a lot, it works that way. Now my next problem is how to find specific information in this data. I could try to parse line by line, as I have a fixed structure. But maybe it would be easier to create a generic xml parsing mechanism. This would also allow for easier export to xml (my next step when reading works flawless).
-
RE: possible to read xml file in custom widget?
thanks @jkandasa, it was probably a problem solved with the most recent snapshot. I updated and it works now with the online xml.
Using a local xml still yields an error, I think there is an error in my call...var myImports = new JavaImporter(java.io, java.lang, java.util, java.text); with(myImports) { var response = mcApi.http().get("c:/file-xml-demo.xml"); if(response.responseCode == 200){ var xmlData = response.entity; } }
using [...]get("c:\file-[...] does not work either, so it's not a problem with slash and backslash.
The html file only contains this:${xmlData}
Using the
run now
option I get this error:TypeError: Cannot get property "responseCode" of null in at line number 5
-
RE: possible to read xml file in custom widget?
well I did also tried your example code and it seems
mcApi.http().get
does not work correctly...TypeError: mcApi.http is not a function in at line number 4
-
RE: possible to read xml file in custom widget?
well the way to access the data is (in my case) not important, I could also use a static parser. I want to open several xml files with all the same structure and extract the data to mycontroller variables. Those could be read and processed in a second step by another script.
-
RE: possible to read xml file in custom widget?
hi,
is it also possible to read a local xml file? And how can I access the different information in the file, are they transfered to the xmlData as options? So would this file:
<?xml version="1.0" encoding="UTF-8"?> <name id="1"> <first>John</first> <last>Doe</last> </name>
be read as for example
xmlData.name.first
-
RE: How to use custome widget
Thank you. Is it also possible to create buttons on custom widget? This way I could trigger the sendPayload only when needed and not always when refreshing the widget...
-
RE: How to use custome widget
Hey @jkandasa
I got a working system thanks to your help. Only one thing that doen't work as I like at the moment: Is it possible to write values to an imported variable?
I have a MySensors value (a number) that has an uidTag and can be read by js file. But how can I change the sensor and have it send to the node?
When I show the sensor in a sensor widget I can change it and it will update at the node.
A side question: is it normal/intended to deactivate focus on these sensor fields every few seconds (update: seems to be the update widget time
)? When I click on the value to change it I have few seconds until it will get inactive and the old value. If I hit enter before that 'timeout' it will update correctly.code:
var myImports = new JavaImporter(java.io, java.lang, java.util, java.text); with(myImports) { var ID = mcApi.uidTag().getByUid("node-ID").getResource(); } ID.value = 123;
-
RE: About battery level
@bmanos you should declare
int counter
in the header, not in thevoid loop()
. The way you did it I think it will be set to 0 in each loop, never reaching 120. And of course @jkandasa is right, it has to beif (counter == 120)
-
RE: possible to read xml file in custom widget?
Thanks a lot four your code, I will try to refine this and get it working. I will have a local xml file in future, but I think I will find a good tutorial for this in the web.
-
RE: About battery level
Hey,
I have a sensor working also using the readVCC lib as in your working example. But I don't see any obvious problem in your example using the voltage divider to read the battery voltage. Maybe you have a problem in your hardware connection to pin A1?
Also one suggestion: between sending 2 messages, I prefer to include a wait(50). I had problems with lost messages when sending too fast, maybe my caps were depleted and my voltage dropped during sending.
For your other problem I know how to do this, here an example:int counter=0 void loop() if counter=120 { sendBatteryLevel(batteryPcnt); counter=0; } counter++ sleep(30000);
That way your battery is transmitted only once an hour, I use this also for my own sensor and it works great.
-
possible to read xml file in custom widget?
Hey @jkandasa,
first I have to admin: I'm a total js dummy...
I tried to create a dropdown list and read data from a xml file to fill this list.
I used this online tutorial http://www.plus2net.com/javascript_tutorial/xml-xmlhttprequest.php but when I try it I getReferenceError: "window" is not defined in at line number 5
. Can you help me how to read this file or is it not possible? -
RE: About battery level
In case you can post your sensor code here I can have a look at it. Normally you just use
sendBatteryLevel(batteryPcnt);
in your sketch and it will be send (I think) with sensor ID 255 to the controller -
RE: How to use custome widget
Well I tried, but did not get any useful output. Could you please give me an example code for reading node 1 sensor 1 and 2 and node 2 sensor 1 and 2? Do I have to cascade
.getAll(node).getAll(sensor)
? -
RE: How to use custome widget
Hi @jkandasa,
of course the html file code was a copy/paste mistake, it looked as you said.
Upgrading to the latest snapshot did the trick, it's working now. Thank you very much (in this specific fact and for your amazing controller)
One last thing: is there a way to read sensor information without defining a UID for it? I plan to build 5-10 identical nodes sending about 10-15 values each. Defining UIDs for each of them would be some work, maybe I can also adress them using kind of gateway>node>sensor terminology. -
How to use custome widget
Re: How to show several sensor readings in a single widget
Thanks @jkandasa for your help. I had to let this project rest for some time, but returned now.
I tried again without luck, so I decided to reduce the code to the bare minimum.
I defined the UID:
The Script file:
var myImports = new JavaImporter(java.io, java.lang, java.util, java.text); with(myImports) { var temperature = mcApi.uidTag().getByUid("Temp").getResource(); }
and HTML file:
<div>Outside temperature: °C</div>
But I still get the error when testing the html with script:
Realy don't know how to solve this (and been thinking about it for half a year)...