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 3 months 3 weeks ago #18097

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 492
  • Thanks received: 46
OH MAN! I just re-read your post Jon and you said reversing the bits in a byte, as in turning 76543210 into 01234567 or reversing the bit order. Is that what you meant?
If so, my first guess would be to shift right into a byte using shift left. I'm a fan of not spending 256 bytes in a lookup table when it can be done mathematically.
Or I found this on StackExchange and I cannot wait to reverse engineer it!
unsigned char reverse(unsigned char b) {
   b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
   b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
   b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
   return b;
}

Hacking my new SafePet Rotating Litter Box for Cats 3 months 1 week ago #18099

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 492
  • Thanks received: 46
The handshaking between systems is almost complete. Most of the snags were created by me. Oversights really, that needed a more polish. The system message packet (SMP) I came up with works great, allowing messages to fly around the same serial bus without interfering with manual input and output.

Today I am hopefully not going to break that, as I add a few features to the SMP. including a simple checksum and some parameters. I flirted with the idea of sending and receiving MQTT messages around the system, but the overhead was a bit too much for the smaller systems, and the managing MPU system can handle all that. After all, communicating with Star Fleet (the host server) is its job. Managing its crew of smaller systems is its job too but with a simpler communications protocol.

A SIDE FEATURE - Something that popped up that I want the host server to know is the messages the project's managing system generates while starting up and connecting, so I am exploring writing these messages to a SPIFFS memory bank as a cache, to send to the host once a connection is established.

That is where I am at. NEXT will be translating the MQTT messages the project's manager gets into SMP format if something is directed to a sub-system from the host. This will give the host manual control of the sub-systems if something specific is not coded yet in the manager. No hierarchy likes it at all when a director works directly with a laborer, bypassing the chain of command, but sometimes it is just... necessary. :)

Hacking my new SafePet Rotating Litter Box for Cats 3 months 6 days ago #18100

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 492
  • Thanks received: 46
I would like to mention real quick an online resource I found that has helped me test out C++ code snippets and functions. I was chasing my tail for a few days until I found this site, and tested simple versions of what I was trying to do.
OnlineGDB beta online compiler and debugger for c/c++
Sign up and you can download what you work on. I cannot say how effective it is for complex project code, but for testing out things like functions and passing pointers, memmove, etc. it has been a God send for me.

Hacking my new SafePet Rotating Litter Box for Cats 3 months 6 days ago #18101

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 492
  • Thanks received: 46
In my previous post, I mentioned using an online tool to diagnose an issue I was having with code I am writing for a sub-system, on a STM32F103C. Before I found this, I was writing my code in Arduino IDE and even though it compiled correctly, when I ran it, I got the same weird response from the device. I now know that as some sort of system error, and the firmware I am using blinks the on-board LED quickly using PWM to make it appear as it is fading in and out. Now that I know what the behavior is, it seems a bit elaborate of a signal that a segfault or overflow occurred, but at least now I know that although my code passes compilation, it was doing something the system did not like.

I tried several things to solve whatever was causing the issue, but trial and error always ended with the fast fading blink in-and-out behavior. This is when I tried the online resource to write and test different approaches to what I was trying to do. Once I was successful at that, I adapted it to my project and sure enough, it worked!!

I now know it will soon be time to figure out how to debug my code in real time in the system I am coding for, but I have never been able to figure out how to do it with the STM32F103C in the Arduino IDE. And since I cannot seem to successfully program the module with PlatformIO on Visual Code, limited compilers like Kiel, or Eclipse, Arduino IDE remains my IDE to code with. Yeah, I know, it sucks. Being limited I mean. Arduino IDE, for some of its limitations, has been a real workhorse for me on both the ESP8266 and the STM32F103C. I miss my Eclipse environment though that I code JS and jQuery, AND PHP in. I'll figure it out... someday.

But wrapping my skull around a new IDE for this specific work on these platforms would deter me from my project completion. So I will wait until I am finished with this beast, then go after a new and more powerful coding environment.

For what it's worth.

Hacking my new SafePet Rotating Litter Box for Cats 3 months 5 days ago #18102

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 492
  • Thanks received: 46
A bunch more stuff for today and tomorrow! YAY!

I am implementing a simple checksum and decided to try Fletchers8, 16, and 32 for the system message packets. I will test a series of messages using random commands and cycle between each method. This will be a benchmark of sorts, so I will look at all the data after it runs for an hour and see which one I choose.

Also... I decided to run a NTP private server on my linux home server for my embedded projects. This way, I only need to update the host server every hour or so, and all the IoT clients will be in sync with the host. I will code for redundancy so if the host is down, the time will come in from outside my private network. A simple broadcast message from the first "PROJECT MANAGER" should keep the others from doing the same thing, and the first lucky project manager to get a successful NTP from the outside world will supply the time. I have not tried running a NTP server on a ESP8266 or a ESP32 but I guess that will be needed also.

Hacking my new SafePet Rotating Litter Box for Cats 3 months 16 hours ago #18103

  • hop
  • hop's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 492
  • Thanks received: 46
I finally got platformio (on VS Code) working for my ESP8266 and my STM32F103C. YAY!
It is so much nicer to code in this environment than the Arduino IDE, and the sketch import feature worked almost flawlessly after I worked out the Arduino extension settings. And I am also using VS Code to write my python scripts too. I just wrote a rather complex one that was so easily ported from Windows to Linux!! I am a believer now, although debugging requires a pay-per-month account. For all the debugging I do, that might be worth it for me.

Soon I should have it figured out how to build all my project's environments and flash the code for each system, all with just one click. This is definitely going to save me time because in Arduino IDE, I have to change the target information every time I switch systems.

The problem I was having when flashing the blue pill clone (STM32F103C) was that I had the wrong protocol set in the platformio.ini settings. It had to be set for mbed instead of stlink. I also had to omit the upload_port setting. Not sure if it is because I am using a nucleo board's STLINK built-in interface that uses MBED. The older discovery boards use a different firmware. For the ESP8266, my problem was that I had the serial lines from the blue pill connected to the rx/tx lines on the wemos d1 mini pro during flashing. I do not have a software solution for that, so I have to remove those lines each time I flash the ESP. So it is not completely "hands-free" like I would want, but it is getting there. Perhaps a 3-state buffer on the serial lines that is only active when a pin on the wemos is toggled low (or high), and floating when it is not in normal operation. Hmm! Maybe I can use that port to send a signal to the blue pill so it knows when to make those serial lines floating inputs, and turn off serial reception so it does not get the ESP flash data erroneously. That would save on the extra buffering hardware. :)

AFTERTHOUGHT: I will have to code to attach an interrupt handler for the serial port enable pin, so the blue pill can get that signal and act on it immediately. I have no idea why I didn't think of this before! The bad thing is that I am up to two control lines from the ESP now... one is blue pill reset and now the other is serial enable. Still though, there are may GPIO lines, and all the ESP is doing is managing communications and operation, and not accessing any additional hardware. That is the blue pill's job. I'm sure there might be a better way to do this, but adding an additional line of control is the easiest at hand.
Last Edit: 3 months 16 hours ago by hop. Reason: afterthought
Time to create page: 0.258 seconds