Hello,
I am a student who would like to use PXT to let users program an industrial robot. There is additional (non-web) software running on the server that can parse and execute instructions. Currently I am trying to get familiar with https://github.com/Microsoft/pxt-sample but cannot solve the following issues:
- How can load/store PXT projects server-sided (shared projects)? I found a “cloud” option in
pxttarget.json
but no helpful information on what it actually does. What would be needed to implement such cloud?
- The pxt-sample project saves
.mkcd
files to the client disk. However, the file magic does not match the UF2 specification. How can parse this format, or replace it with my own?
- Share links are not supported for static-pkgs, as they are part of the backend server. Our backend implementation is unfortunately not public so you’d have to implement a version of your own to support this; that is, implementing a
api/user/project/share
post endpoint which stores the project and gives back the proejct id, as was as an endpoint to display the shared project.
- the .mkcd file it’s giving you is an LZMA compressed json blob of the file; that is, something like
{
"main.blocks": "<block stuff goes here",
"main.ts": "function myCode() {...}",
"pxt.json": "{...}"
}
we can decompress it in the webapp with pxt.lzmaDecompressAsync
, or you can find another format as needed. That save button goes through this path (assuming you don’t turn on the flag for saving as a png, which would be harder to match the parsing for): https://github.com/microsoft/pxt/blob/master/pxtlib/package.ts#L1288.
Note that this is the ‘file save’ portion rather than the hardware support, since you mention targeting a device / uf2 output you might want to take a look at pxt-maker here https://github.com/microsoft/pxt-maker to see a bit on how it’s done as there’s a bit more involved than I can describe without more context. the supported variants section in pxtarget.json might be a good place to start, as that describes the different chips supported – e.g. here’s one of the prs that added rp2040 in https://github.com/microsoft/pxt-maker/pull/349
1 Like
Thank you for this incredible fast answer!
Yesterday I spent a few hours trying to figure out how this share feature works in order to implement the required API/endpoint. Unfortunately I am a novice when it comes to web development, which might be the reason why I am somewhat overwhelmed by the complexity of PXT.
It is however good to know that the mkcd file could be parsed after downloading to e.g. a shared drive, as an alternative to simply exchange project files between the dedicated robot control logic and the PXT GUI. I do not need UF2 output - it just happens to be the only documentation about saved files that I could find. As long as I can somehow convert my blocks into custom code (and back) it’s fine.
In the meantime I also experimented with Blockly which does not look as good but has a great documentation and is noticeably faster to compile/run. Since there’s less API to get familiar with, I might get to my goals quicker by writing my own code than to understand and modify the PXT structure.
By using Blockly I quickly reached some progress without digging through the source code too often. If that approach turns out to be too limited for my use-case, I might return with follow-up questions but as for now it seems to be “good enough” for my requirements.