Some quick screen shots. I have to think a bit about syntax...
http://127.0.0.1:5000/train/20 -->
{ "control": "Legacy", "direction": null, "labor": 12, "max_speed": null, "momentum": 0, "road_name": "Delaware & Hudson", "road_number": "0020", "rpm": 0, "scope": "train", "smoke": null, "speed": 0, "speed_limit": null, "tmcc_id": 20, "train_brake": 0, "year": null }
http://127.0.0.1:5000/acc/15 -->
{ "block": "on", "road_name": "Upper Main North Power District", "road_number": "0015", "scope": "power_district", "tmcc_id": 15 }
http://127.0.0.1:5000/sensor_track/50
{ "last_loco_lr": 255, "last_loco_rl": 255, "road_name": null, "road_number": null, "scope": "irda", "sequence": "slow_speed_normal_speed", "tmcc_id": 50 }
http://127.0.0.1:5000/acc/50
{ "road_name": "Upper Main West", "road_number": "0050", "scope": "sensor_track", "tmcc_id": 50 }
http://127.0.0.1:5000/switch/1 -->
{ "road_name": "Gantry 1", "road_number": "0001", "scope": "switch", "state": "thru", "tmcc_id": 1 }
I'm trying out the flask-restful package. It only took about 40 lines of code to generate this output. If others have suggestions for restful-api frameworks that they've used in Python, I'd love to hear about them.
What's interesting is that I've basically written a wrapper around the PyTrain CLI, I can literally issue any dmcc/legacy command I want to. I will probably write simplified POST handlers for speed, direction, bell, horn, and any other common engine commands, but then I'll add an endpoint that takes a CLI command, giving me access to the entire Lionel command set.
-- Dave