Welcome, Guest
Username: Password: Secret Key Remember me

TOPIC: Hacking my new SafePet Rotating Litter Box for Cats

Hacking my new SafePet Rotating Litter Box for Cats 4 months 6 days ago #18138

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
I am working on two pretty simple things for my websockets interface for the ESP8266. One is something I have been needing on this project from the very beginning... the ability to output serial debug messages to a terminal-like control on the served web page. This is not for end-user stuff, but certainly helpful with development of the ESP8266 code. I also found a neat terminal-like interface written in JS and jQuery that acts like a command interpreter. That is for later, I just want the serial output to show on the served web site.

It should be easy to do since javascript will do most of the heavy lifting. Serial.prints are rerouted to websocket output and javascripting acts on it and controls the web page DOM to display the output. Pretty cool! I will include a text input control on the diagnostic page to allow keyboard input into the ESP8266 back the other way through the websockets connection. There is probably a library out there that does this, but instead of shopping around, I'll just write it myself.

I also dug into drawing graphics via javascripting onto a canvas object on the served HTML. Since all this is running on the client machine, I should not have to worry about bogging down my embedded device. With this new feature, I should be able to show real time data as it is acquired, on the served web site interface. For this project, it will be the occurrences of motion detection via the two sensors I have been working with.

To make this a complete test bed, I included a trigger GPIO line that will signal my video capturing project when an event occurs. This can also be a websocket message with the host server. Then I will be able to sync video on the host embedded server and see what triggered the sensors. I had to dust off my research in order to embrace the "roll back" feature of the video capturing, meaning that when an event occurs, the system knows to save X-number of seconds prior to the event trigger. So I will get y-number of seconds of video with the event trigger being the moment in the middle of the capture length. The video being captured will be continuous, feeding a file like a buffer. Derek Molloy of the Dublin University did amazing things with the beaglebone black on this very subject so I will have to dust off that board too. The only caveat is that I want to use my PI camera system instead of the USB web cam he used. I do not want to get too sidetracked with the hardware retrofit.

That's it, research and ideas a plenty. Lots of coding to do. More when I code it. :)

Hacking my new SafePet Rotating Litter Box for Cats 4 months 1 day ago #18139

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
A LITTLE UPDATE!

Still working on the served web page interaction and websockets...

I have figured out how to successfully route the ESP8266 board's serial print output to a broadcastTXT to connected websockets and display it in a terminal-like control on the served web page. This is just one more step towards fully cutting the cord (USB cable) and still have the ability to see debug messages embedded in the code that normally shoots out the serial port via Serial.print and Serial.println. These features will exist on a diagnostic/debug page served from the ESP8266. I have been wanting to do this for a long time.

It's done via static functions in the sketch at the moment. But once I get it perfected, I'll move it to a library to take full advantage of function overloading to handle any variable type sent to it and behave like the Serial.print method does. Also added was a function that uses STRCAT to add a control header to the messages so the javascript knows it is a serial out message and where to apply it in the web page DOM. Using this, I can specify message "ports" so I can categorize the messages as debug, notification, etc. types for sorting amount multiple terminal controls.

Also in the works is a command interpreter that acts much like telnet but is much more responsive.

That's it for today, or at least the next few hours. THANKS!
Last Edit: 3 months 4 weeks ago by hop. Reason: header text too big. 5 works!

Hacking my new SafePet Rotating Litter Box for Cats 3 months 4 weeks ago #18143

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
SERIAL OUTPUT ON WEBPAGE VIA WEBSOCKETS

I was finally able to get the serial output from my ESP8266 board to route via websockets and javascripting to the served web page. It wasn't easy either! But now that I have done it, it's a matter of wrapping it up into a library. This is what I am working on today. This is an incredible discovery for me!!

And the serial prints can use channels, so the serial prints can be decoded and routed to different objects/controls on the HTML DOM. The same engine is also used to route other output that is used to control button states, timer count down displays, graphs, etc. This is a lot of fun implementing!!!

I started taking time documenting all this for an article here including youtube video. What I do not know yet is how to record video directly of screen activity and adding voice narrative. I just never considered it before, but something like this would REALLY have helped me so that is how I am learning to present it.

Worth noting... I ran into tons of exception errors and watch dog restarts on the ESP8266 platform during the crafting of this feature. One of the main reasons was sending data through a websocket connection that was not made. I used a global variable to be set true or false depending on connection status. If there are no connections, the output just routes to the serial port.

Activity has really ramped up on this project as of late. More frequent updates are coming.

Hacking my new SafePet Rotating Litter Box for Cats 3 months 4 weeks ago #18144

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
SERIAL OUTPUT TO WEBPAGE - CHANNELS

One of the things I have learned about classes is that you can create objects from them. This solves the issue of having to include a channel number on every "print". Each object can be created, properties like channel type and number can be set, and then the object name can be used to send the data. Right now, I'm just doing text with this. But after it is all solidified, I will add support for binary. This would be more helpful for raw data for graphics, but right now, it is premature.

What impact this class will have on memory is yet to be determined. As I can envision many objects instantiated by this class, how they impact resources is certainly something to consider.

It is worth noting as I have so many times before... I am definitely no software engineer. A very large majority of my knowledge is self-taught by doing. Because of this, there is most-definitely flaws in my designs and techniques. When giving me feedback, a better way of doing it is certainly welcome, but please do not flame me for the way I create this stuff. It is and always has been a very long journey for me to get better at what I do in this field, as real life allows for time. I always feel that as long as I progress, I'm happy! Even if you need time-lapse photography to realize my progress. :dry:

Hacking my new SafePet Rotating Litter Box for Cats 3 months 3 weeks ago #18146

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
I almost had my custom class completed but could not figure out how to pass the websocketserver object instance to the class so that it could be used. This is not a deal breaker, although I will continue to pursue the solution. In the meantime however, I will just use what I have inside the main sketch, using parameters to deal with the channel information. I can define those in both the sketch and the javascript so I do not have to use channel numbers, which can get confusing.
With 2 digits for the channel number, I can have 99 different channels of communication with the webpage through one websocket. That should be more than enough to break things up, for now. :)

Hacking my new SafePet Rotating Litter Box for Cats 3 months 3 weeks ago #18147

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
PHANTOM SLOW DOWN CAUSES ME TO CHASE MY TAIL!

I am so glad I used several techniques to eliminate a problem before I got too far down endless rabbit holes chasing the wrong issue, thus chasing my tail!

For some reason, when accessing my ESP8266 served web site using websockets, it got really slow. It was fast and snappy just seconds before on my PC! I had made a lot of code changes and added a lot of features. I was rolling along and didn't want to frequently stop to test my work, and got bitten in the behind when I decided to try my changes using my smart phone. Websocket communication ground to a slow death, with minutes needed to respond to my web actions. I started chasing the smartphone issue and ran around a bit, wondering why websockets were so slow on a smartphone. After all, it was just quick as lightning on my PC seconds before. Apparently, the slowdown conveniently happened between when I left my PC and picked up my smartphone. I hate how these false-positives happen conveniently during transitions!!!

It was the ESP8266 actually. Testing the same site on my PC again confirmed it. I reset the device and now all devices are snappy again.

What caused the slow down is a mystery right now but it is enough of a concern to chase it later, actually very soon after I get this all put together. I cannot have one of my autonomous systems act this way while unattended, and I need to either fix the code or place a watchdog to reset when it happens.

Websocket interaction certainly is not going to be as fast on my smartphone, a Samsung Galaxy S9 Plus, as it is on my main PC or beefy laptops, but it SHOULD be fast enough to give me almost instance response to button clicks and websocket requests, and certainly fast enough to display a text message showing a count-down time of a timer sent every second. I was getting 5 second delays with that! :(

So far, I have NOT been able to recreate the issue. I even tried maxing out the connected clients, but each client updated as if it was the ONLY connected client. Hardly any visible delays at all. Hmm.

With all the strings, pointers, references, classes, and passed objects by pointer, I probably have a memory leak somewhere. Hmm. It might be good to find a way to report that... system ram available as a websocket message for my debug column on my web page. I love this forum! Writing about this stuff helps me to think things through!

So that is where I am going tonight, to report system resources via websockets to the served viewed web page.

Also completed... the message channel protocol and the debug window that shows debug output from the ESP8266 as it would be shown via serial.print commands to the Arduino serial console. Except that no USB connected cable is needed. I am close to adding smooth scroll and custom-selectable scroll-back line buffering as you would expect to see in Putty for example. And a toggled timestamp on each outputted line. It is SO cool!!

NOTE - Google Chrome tools at diagnosing and tweaking my HTML, CSS, and Javascript has become an invaluable tool! I just discovered a feature that allows me to toggle the view between PC (current machine) and mobile device! I had to add a custom device for my Galaxy S9 Plus though, but that was easy enough. Now it looks just like it would on my phone. Without orientation switching of course. I haven't figured out that tweak yet.

Thanks for reading! Wow, 11,900 views of this thread so far! I hope to have some screen shots and narrated video soon.
Time to create page: 0.254 seconds