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 4 weeks ago #18131

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
To Recap: The system uses a Wemos D1 Mini (ESP8266) with 4mb of flash. 1mb for code and 3mb for SPIFFS. It runs a websocket server at a static IP. Files in the SPIFFS include a few HTML files (pages) and a javascript file. The JS file handles communications between the clients served web site and the Wemos device. One of the web site's pages handles file upload to the SPIFFS. Currently, the Wemos firmware is updated using OTA and the web files are updated using a web page and JS functions.

For IDE's, I am using Visual Studio Code to edit the SPIFF files (HTML, JS, CSS) and Arduino IDE to edit and upload the Wemos firmware. This multi-IDE approach is because I still have not been able to get PlatformIO on VSC to do OTA successfully. It's not a concern although it is inconvenient.

The Wemos is deployed, controlling the cat box. So far I have not needed to pull it and plug it in with a USB cable to update (knock on wood!!).

Simple operation of having a static timer triggered by a button that keeps the cat box running for 2 hours. I have been able to send timer updates each second back to the served web page on the client, and interrupt it with another button click. I am in the process of improving on that and adding a sensor to detect movement.

More on this whole process soon.

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

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
SENSORS - VERY FRUSTRATED!

I have a bag full of PIR sensors but I am having a heck of a time getting them to work. I adjust the potentiometers to what I think will work, but I either get a pulse that always fires or something that works but with a lot of false positives.

So I am now going with a microwave sensor. They are expected to arrive Saturday. I will test then add to the project.

In the meantime, the controller is working great! Albeit static timing... meaning I can trigger a "cleaning" any time I want with my phone, or let the periodic timer trigger a cleaning every 6 hours, or 4 times a day. In the end, that's 4 times a day without interaction opposed to running 24/7, for a net return of power savings of 1/6th the previous required amount.

But now I am ready to add object detection in place of the static timing. Just need reliable sensors for that. More when that happens!

Hacking my new SafePet Rotating Litter Box for Cats 4 months 2 weeks ago #18134

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
Going after a radar/microwave solution for the sensor. Working out the bugs with false positives including filtering of the power supply, software considerations, etc. This will allow the project to be fully autonomous!

So far though, the web interface combined with a static 4 a day timer has worked WONDERS for keeping the cat box happy!

I know, I know, where is the @#^*@&#%()(!@# documentation?

It's coming! Work has me running in circles! I miss the days of my youth where I can put together a NICE tutorial guide without worries of using my precious available time.

More IS coming.

Hacking my new SafePet Rotating Litter Box for Cats 4 months 2 weeks ago #18135

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
OK, the start of the documentation. I want to clean up the code first before I post it. PLEASE keep in mind that the code is some of my own, and parts from others. I will try to include the sources and authors in the comments. I made a lot of changes, adding, tweaking, so it will not be easy.

To summarize... (SOFTWARE)
ESP8266 - Wemos D1 Mini 4mb
I am using a Wemos D1 Mini Pro 16mb but the configuration is exactly the same. I burned up my last D1 Mini and waiting for more, and I had 4 Pro versions that work the same, and the code is exactly the same. 1mb code, 3mb SPIFFS.
The code utilizes OTA support so I can upload code using my Arduino IDE 1.8.9 Hourly build. The hourly build was necessary to eliminate long build times without adequate caching, without moving to the buggy 1.9 version. I can upload the sketch using a static IP address that shows in the IDE.
Also included is a websockets server, and is configured as a WAP with SSID. I am not sure at this point if I want to eliminate the WAP features since I access the device through my wireless LAN. This might be useful in the field without that wireless LAN support so that is for later.
The IP is statically set, along with the other settings like network mask, DNS, gateway.
The webserver files are from the onboard SPIFFS and can be uploaded/updated using one of the uploaded pages. One of the files included is a javascript file that binds the served webpage on the client to the Wemos board hardware. This is also bi-directional.

That's it for right now. Dinner is ready and then I have to go to bed. I'll elaborate more on all this tomorrow.

Thank you for your patience!

Hacking my new SafePet Rotating Litter Box for Cats 4 months 2 weeks ago #18136

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
MOTION DETECTION:

The cat box controller is working fabulously, but other than manual triggers from the device-served web interface, the cleaning process is pretty much static with an automatic trigger every 6 hours. It is working great! But it is not the original idea at all. To get the cat box to be more efficient, I need a motion trigger set off by the visiting cats.

I tried using a PIR but failed. As it turns out, the failure was my fault and not the PIR module. Yeah, yet another line or two of faulty conflicting code. I had already transitioned to a microwave motion detector that is working GREAT post-code fix, and I will probably either go back and test the PIR now that the code side is fixed, or include it as an extra sensor.

But before I include the motion sensor on the target device, I have to test it. To make this testing phase go so much easier, I broke out another ESP8266 device (same Wemos D1 Mini Pro) and loaded with the same firmware and web files. The only thing I changed was its SSID to be the same as the target with "LAB" added at the end, and the static IP to be x.x.x.51 instead of x.x.x.41. Both devices are working great! Now I can test my new code revisions on the "LAB" device on my bench, and once tested and working, upload it to the target device. Neat idea! Why didn't I think of this before? After all, so many have done this and written about it. Sigh.

So to test, I will be adding a couple of features to the LAB unit. One will be another interrupt handler to deal with low/high transitions on the motion detector pin I picked (D5). Another feature is off-board and will be a cron job on my home linux server. A python websocket client to handle trigger messages from the LAB unit and record them with date and time stamp into a simple SQLITE database. On the LAB unit, I will have to add code to send the trigger messages to the python-connected websockets client, the irq handler for pin D5, and modify the web files including the javascript support to display these events on the served web site.

Lots to do but should be pretty easy stuff. Then I can put the thing in a closet, a box, in a glass enclosure (glass absorbs the RF energy and does not reflect, like a shield), etc. This data will tell me about any false positives I might experience so I can add power supply filtering and adjust the software to accommodate the anomalies.

EDIT: I am considering adding a camera to the LAB unit, controlled by a separate system, a RPI B+, that uses the same triggers as the python client on the home server. This will give me a picture of what (if any) object triggered the motion detection. I am not going to get too hung up on this part though. If it gets complicated, I'll shelve it for later projects.

Thanks for reading!
Last Edit: 4 months 2 weeks ago by hop.

Hacking my new SafePet Rotating Litter Box for Cats 4 months 1 week ago #18137

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 526
  • Thanks received: 46
DISTRACTIONS - BEING SIDE TRACKED!

Long delay because I got sidetracked again. This time it was figuring out how I can plot live graphics (a waveform, charts, etc.) on my served web page using javascript and websockets. Then one thing led to another. I figured out the bidirectional communication, but then I had to figure out how to send binary, then different data types, then enter JSON encoding and decoding, and I am almost there. Yes, all to figure out the paired patterns of using my radar and PIR sensors.

Also got sidetracked exploring CSS techniques for drawing the embedded web page. I also got sidetracked with serving the heavy web resources from my local embedded server. That was of course my HOME server so I went after building a new home server strictly for my embedded systems. Along the way, I was experimenting using SQLite database operations using Python, but then I needed something stronger than using NotePad++ for writing my Python so I got side tracked (again yeah) setting up Py Charm so I can write awesome Python scripts. Then I also got side tracked (again) modifying my SPIFFS file upload handler to up a web site package instead of one file at a time.

I guess this whole project unlocked a lot of options for me and my embedded systems designs, and being the undisciplined chap that I am, I run with those ideas without the willpower to just stick to the task at hand. Easy to do in this genre of science, when you want to do something and are not only faced with one door to go through, but many!

Anyway, the two sensors are performing perfectly! I just need data on how they react to my cats to tweak my code to use those sensors adequately. I am doing that today and will not stop until I have a good test bed set for some good sampling over the next day or so. I wrote a few python scripts that let me access the board and control it from my embedded server, and log events to a database with timestamps, etc.

I also took a lot of screen shots and wrote notes. After this is all together, it should be a simple exercise of piecing it all together.

Thanks for reading!
Time to create page: 0.336 seconds