ChipChop Support Forum
Log in
Log out
Join the forum
My Details
REPLIES: 3
VIEWS: 206
BACK
REPLY TO THIS POST
Aubrey44
16 Feb 2024
Couple clarifications on potential code use and checks.
Im not the best at understanding code and .h / .cpp files. I think there is a way BUT ...

1. is there a way to confirm the device is "connected" to ChipChop? Say through "(connected) / (!connected) or (connected == 0) / (connected == 1). To code in some connection management code for whatever reasons...

2. Trying to use numerical slider to input a value (say, "temp_setting" for thermostat) into a global variable. What would the function callback look like?




    void ChipChop_onCommandReceived(String target_component, int command_value, String command_source, int command_age){

    If (target_component == "temp_setting"){
        temp_setting = command_value;
    }
}





3. This segway's into #3 nicely... maybe a numerical input example in the future docs/examples? LOL??

4. Is "ChipChop.run();" function blocking in any way (that you know of)? Is it safe to use loop() for all of my code?

5. future ideas.... keep in mind i have no idea of how hard this is.
- radial, gauge like meters for view only/numerical value widget
- historical state (1 day, 3 day, 1 week) charts of components

Keep up the good work and sorry for long post. Thought maybe peoples would benefit from all the questions and answers in the future.

thanks
Gizmo
16 Feb 2024

Hi Aubrey,

It's not a long message at all, the more you explain the easier for me to answer (most of the time :-), don't worry my answer is going to be wayyyy longer!

Ok, let's start from the top:

1. is there a way to confirm the device is "connected" to ChipChop

Yup, you were on the right track. The main way is to use ChipChop.connected it's a boolean variable (not a function...so no brackets at the end) and you can check it at any time like this:

if(ChipChop.connected) or if(ChipChop.connected == true) or if(ChipChop.connected == 1) it's all the same

The ChipChop.connected "should" only ever be true if: there is WiFi, the socket connection has been established, the handshake has been fully completed and the ChipChop engine has sent a welcome message.
And if for any reason any of these conditions change "connected" should drop to false (0)

2. numerical slider to input a value

Your plan was good...but...one thing to keep in mind, the "command values" are for flexibility sake always sent as strings.
That means that"overloading" the ChipChop_onCommandReceived and changing the "command_value" into an int() wouldn't really work.

It's actually quite simple if you know that the value for some component will be coming as a number is to "cast" it to the corresponding data type - to.Int() or .toFloat() or .toDouble()
That allows you handle anything in the same ChipChop_onCommandReceived callback




void ChipChop_onCommandReceived(String target_component, String command_value, String command_source, int command_age){

        If (target_component == "temp_setting"){
            temp_setting = command_value.toInt(); //<< simply cast to to.Int() or .toFloat() or .toDouble()
         }
}



3.... maybe a numerical input example in the future docs/examples?LOL??

I have heard from a reliable source on TikTok that that particular sentence means that you have volunteered yourself to write all future ChipChop documentation and the "LOL" in caps with two question marks at the end signifies that it's all legally binding.
Well, thank you so much for your sacrifice, I always knew that Canada is a great nation 🍁💕. I will send you shortly the few hundred pages I've never managed to finish, don't rush and I'll leave the choice of font to you!

I agree, in the library examples > all_functions.ino between lines 73 and 78 it is a bit unclear and easy to miss (I honestly do)



        //EXAMPLE: command sent to a component called "brightness" that expects an integer value
        if(target_component == "brightness"){
            // do something here to change the brightness to the received percentage....
            int brightness_percent = command_value.toInt(); // or .toFloat() or .toDouble()
        }



4. Is "ChipChop.run();" function blocking
- The short answer is...no, it's not blocking as I don't like blocking stuff
- The long answer is, that was a small lie, yes there is one place on line 257 in the ChipChopManager.cpp where a delay was necessary in case you go trigger happy and start firing triggerEvents like mad.
- The even longer answer is that I have completely re-written the way events are handled (at the great sacrifice of mr @Hossrod who is helping testing it) and I am hoping to tidy it all up in the next few days and publish it. It will be vs. 1.40 and there won't be a single blocking line of code anywhere. You won't need to change anything in the existing code but there will be an extra little feature added if you want to use it.
- Important: You should avoid using delay() in your code if you can help is as it can block the chip from checking the websocket buffer so you could miss something. ESP's aren't too bad handling delay() and on dual core processors it could be possible to completely move the sockets from the main loop(), if there is enough need/interest I could look into that. But, in general you will be better of using non-blocking methods if you can.

5. future ideas

Don't worry about how complicated it is, it's only code and any suggestion is a good suggestion (unless it's a stupid suggestion)

- I have already prepped a radial gauge and honestly I want it out there but I really need some constructive input...where/how do I integrate it in the interface?
I want to do a complete redesign of the app and that was kinda the plan to do it at the same time but if you have any suggestions how you think it could work in the interface please jot something, don't care if it's on a back of a napkin. (I know you are busy writing the docs, so no pressure)

- Historical state is already possible using the "small log" option for up to 3 components per device. There is no time limit though, so if you don't have large data you should be able to easily store 2 weeks at 10 min logs per component.
@jnogues is already on my ass for couple of weeks for a "graph" log display and it will be out soon.
I have to impose some limitations on the log simply to reduce the storage costs but I am working on some options.
So, I don't know, is that's what you meant with historical state?

Actually I just thought of an interesting concept...hmm...I need to have a little think...I'll get back to you (everyone)

This was a proper long answer! Let me know if I've missed something or you are not sure...all this really benefits everyone

Right need to dash now, laters 👋



Aubrey44
16 Feb 2024

Hey Gizmo,

So it was all there, my brain knew it was but I couldn't quite decipher everything I have read about ChipChop lately. I just had to look a little harder and process a little longer... You nailed every answer bang on for me. Thanks for that.

Honestly... If I didn't have four little kiddos running me ragged at the moment I would hop right in there and help you with documentation! I really do think the documentation is quite accurate and great really. Considering what else is out there.

Again not knowing what is involved but just to give you ideas for long in the future cause you asked.. I envision you having the option of different layouts, differently shaped buttons/switches and indicators. And once you really get your app going, the ability to move around the buttons/indicators/gauges/charts as one sees fit. i forgot to throw charts into my beautiful renditions!!! hahah



Attached images
Gizmo
16 Feb 2024

damn...4 x sproglets vs. 1 x Gizmo, no competition there... you are off the hook.
I'll go and throw a bucket of typos in the docs now, just need to wait for the first OCD complainer...and ...bam...new "volunteer" in the bag :-)

Hey, seriously, what you have described is pretty much my vision. I was at first thinking something like a phone screen layout with app icons & widgets but if I'm going to spend some serious time building it then may as well try and make it better than Apple & Google...right...lol?

It would require some sort of App Design Studio in the Dev Console I think, that's gonna take most of the time. When I make some progress what I'll do I'll setup a little test server with shared access so everyone can play and comment.

Ok, that's on the list now...thanks for the input dude. I'm going to print and frame your artwork as a historical memento!