repository to manage all files related to the makeathon farm bot project (Software + Documentation).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

communication_handler.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from flask import Flask
  2. import time
  3. from sensors import readSensors
  4. app = Flask(__name__)
  5. @app.route("/", methods=['GET', 'POST'])
  6. def hello_world():
  7. return "<p>Hello, World!</p>"
  8. """
  9. SENSOR TEST FUNCTION
  10. """
  11. @app.route("/measurement_test", methods=['GET'])
  12. def measurement_test():
  13. return readSensors()
  14. """
  15. """
  16. @app.route("/temp/<int:sensor_id>", methods=['GET'])
  17. def get_temperature(sensor_id):
  18. if sensor_id == 1:
  19. # here we need to read our sensor values
  20. return "23.4"
  21. elif sensor_id == 2:
  22. return "21.0"
  23. else:
  24. return "not found"
  25. @app.route("/move/<position>", methods=['POST'])
  26. def post_move(position):
  27. if position == 'plant1':
  28. return f"I moved to position: {position}"
  29. # control motors or whatever you like
  30. return f"Somewhere moved, no idea where to: {position}"
  31. @app.route("/all", methods=['GET'])
  32. def get_all():
  33. # read sensor data
  34. # TODO
  35. time.sleep(10)
  36. # put sensor data into a dict
  37. ret = {
  38. "plant_id": 1,
  39. "sensordata_temp":20.5,
  40. "sensordata_humidity": 23.5
  41. }
  42. # return it as json data
  43. return ret
  44. app.run(host='192.168.0.106', port=5000)