Various common models, in order of simplicity and effectiveness:
- License it under a copyleft license. Works the same as what you describe, except s/commercial/proprietary/, and is completely compatible with the FOSS ecosystem. You get paid by any company (or individual) who wants to ship proprietary software built on your code.
- Work for a company that gains revenue by releasing the code, and pays you accordingly. For instance, a company that sells more hardware because of the code.
- As mentioned elsewhere in this thread, charge for compiled binaries, for the convenience of non-developers.
- Provide a paid service based on the code.
- Require payment up front before releasing the software (crowdfunding model). Only works before you write/release the software, and benefits from an established reputation.