fjblau
In my Pin Mapping I have:

PIN: A0
Type: Analog Input
Address: %IW0
Name: PIN_A0
 
In my Program I have a global variable in Resource:

Name: V_IN
Class: Global
Type: UINT
Location: %IW0
Initial Value: 0
 
In my ladder I have a UINT_TO_STRING

IN: V_IN
Class: External
Type: UINT

This value gets passed to an MQTT message on a button push. A Test message works if default.

If I do not create the V_IN in the table for my LD it will not compile:

 [10:01:57 PM]: /Users/frankblau/Documents/OptaTest/CleanTest/build/Arduino Opta/src/program.st:26-74..26-77: error: Ambiguous enumerate value or Variable not declared in this scope.

If I do create V_IN in my table for my LD and make it Type EXTERNAL with no location, the program compiles and uploads but does not run.

If I keep the global var as above in the Resource section and assign the location of the External Class Var in my LD to %IW0 it does not compile:

   [10:07:13 PM]: /Users/frankblau/Documents/OptaTest/CleanTest/build/Arduino Opta/src/program.st:19-10..19-23: error: invalid external variable declaration.

If I remove the Global VAR from the Resource table and make it a local UINT var with Location %IW0, the program compiles and uploads but does not run.

What possible combination have I missed to read the analog value and convert it to a string to send to MQTT?
thiagoralves
What do you mean by “the program does not run”? Is it not behaving as you expect or is it hanged? Do you have a heartbeat signal (blinking led every second or something like it) to confirm the program does not run?
Reply 0 0
fjblau
I am just trying to make a one-shot read of an Analog Value and sending it to MQTT;
 
[203128%2F9653228%2Fmceclip0]
Reply 0 0
fjblau
I get no output when I push the button. If I take out Send_One from rung 3, I do see the Analog Values in MQTT now.
Reply 0 0
thiagoralves
Your logic is incorrect on rung 2. You shouldn’t use a counter for this. Removing Send_One from rung 3 will make it send one message per scan cycle. To send only one message when you push the button, just add BTN_USER with the rising trigger block on rung 3 right before the EN pin on your UINT_TO_STRING.
Reply 0 0
fjblau

[image]



This fires once with no payload after compiling and loading. But nothing happens when I push the BTN_USER
Reply 0 0
fjblau
And with this version it fires constantly:

[image]

[image]

Reply 0 0
thiagoralves
MQTT_CONNECT SUCCESS output stays true forever once a successful connection is made. Connecting the SEND block to that output will make it fire messages every scan cycle, which is not what you want. Avoid putting everything together in a single rung, as that can generate unnecessary complexity and lead to logic bugs like this one.
 
Leave the UINT conversion block on its own rung. Conversions can happen every cycle even if you are not sending messages every cycle (it’s a very quick operation). Then leave the logic to send on the last rung, with BTN_USER, rising trigger, and the SEND block all in series.
Reply 0 0
fjblau
Still doesn't work. I think it is something to do with the trigger... one pulse isn't enough time to send the MQTT message or something? Tried latching it up on BTN_USER and then releasing it with Send SUCCESS but still no luck
Reply 0 0
fjblau
Also something I saw about not using a sinking input (like BTN_USER) on a trigger?
Reply 0 0
fjblau

[image]



This fires once at load and then nothing when the button is pressed.
Reply 0 0
Reply