Beginner Sensor Data Chart



  • Hello guys, I'm new here and wanted to share a simple little start to hopefully a bigger project. This is a great start to getting used to Python and MongoDB.

    Whoever wrote the starter documentation, THANK YOU! I used that here.

    Requirements: Install python3-light, pip3, flask, flask-restful on the Omega. Install plotly and pymongo on the client.

    Source Code

    The code that runs on the Omega is under App directory. This is a ultra simple flask api that reads the temperature. You can configure this to run on boot by adding python3 /App/App.py to /etc/rc.local.

    You will need another computer running MongoDB. Using the other computer you can request the temp and store the data using the App.py script found in Client folder. Using the Graph.py script will generate a cool little graph.
    0_1539810015606_0636b545-878e-4a65-aa46-10b4200908f5-image.png

    Probably don't need 1 second intervals, but this was a really fun and cool way to get started with python. Google truly was my friend and I hope some else looking to use a DS18B20 sensor finds this useful.


  • administrators

    @Frank-Wiebenga very cool so far! make sure to keep us updated as you add to the project!
    And I'm glad you liked the Starter Kit :)



  • I think I broke it :-(

    I soldered up a prototype board using the same wiring diagram for the DS18B20 probe. I was dinking around with it this morning and wanted to add a SSR. I saw that tutorial on the LED control. I didn't think I needed a resistor in place because the SSR isn't voltage specific like an led is so I connected the SSR 3-32VDC to 3.3v + and ground to -. I confirmed I was able to get requests and update the GPIO value. Here is a video of it in action

    from flask import Flask
    from flask import jsonify
    from flask import abort
    import time
    import datetime
    import onionGpio
    from temperatureSensor import TemperatureSensor
    import oneWire
    
    app = Flask(__name__)
    
    
    # setup onewire and polling interval
    oneWireGpio = 19  # set the sensor GPIO
    pollingInterval = 1  # seconds
    
    # Define SSR
    gpio0 = onionGpio.OnionGpio(0)
    # set to output direction with zero (LOW) being the default value
    gpio0.setOutputDirection(0)
    
    
    #Define our data structure
    config = [
        {
            'id': '1',
            'name': 'Mash Heater',
            'gpio': 0,
            'IsOn': False
        },
        {
            'id': '2',
            'name': 'Boil Heater',
            'gpio': 1,
            'IsOn': False
        }
    ]
    
    
    def start_sensor():
        # check if 1-Wire is setup in the kernel
        if not oneWire.setupOneWire(str(oneWireGpio)):
            print("Kernel module could not be inserted. Please reboot and try again.")
            return -1
    
        # get the address of the temperature sensor
        sensorAddress = oneWire.scanOneAddress()
    
        # instantiate the temperature sensor object
        sensor = TemperatureSensor("oneWire", {"address": sensorAddress, "gpio": oneWireGpio})
        if not sensor.ready:
            print("Sensor was not set up correctly. Please make sure that your sensor is firmly connected to the GPIO specified above and try again.")
            return -1
    
        return sensor
    
    
    sensor = start_sensor()
    
    def get_temp():
        value = sensor.readValue()
        return value
    
    
    @app.route('/')
    def hello_world():
        tempval = get_temp()
        return jsonify(
            temp=tempval,
            datetime=datetime.datetime.now()
        )
    
    @app.route('/heat/<heat_id>', methods=['GET'])
    def heat_get(heat_id):
        task = [task for task in config if task['id'] == heat_id]
        if len(task) == 0:
            abort(404)
        return jsonify({'heat': task[0]})
    
    @app.route('/heat/<heat_id>', methods=['PUT'])
    def heat_post(heat_id):
        task = [task for task in config if task['id'] == heat_id]
        if len(task) == 0:
            abort(404)
        print(task[0])
       # Toggle bool
        task[0]['IsOn'] = not task[0]['IsOn']
        if task[0]['IsOn'] is True:
            gpio0.setValue(1)
        else:
            gpio0.setValue(0)
        return jsonify({'heat': task[0]})
    
    if __name__ == "__main__":
        app.run(host="0.0.0.0", port="8080")
    

    However after 167 requests it stopped working. I did get data up until it stopped. Now my Omega2 won't boot, it just gets really really warm. Even with nothing plugged into the usb dock the Omega2 get's so hot you wouldn't want to touch it with your hand. Did I break it for good? What did I connect wrong?
    0_1541164905536_c7aae0d4-f947-4bbc-81ff-dc65a33654cf-image.png



  • i have an omega2+ that also gets very hot. it still boots and seems to run basic things but i do not use it much at all cause i want to take the shield off and hit it with freeze spray and see if a component sticks out. i'm guessing a bad capacitor though could be something else. maybe i'll do it tomorrow. if i learn anything i'll post here.



  • @Lazar-Demin Does the wiring seem correct?


  • administrators

    @Frank-Wiebenga was the solid state relay controlled directly by an Omega GPIO? I could be wrong, but judging by the dead Omega, my best guess is that excess current or voltage from the relay made it's way back to the Omega causing it to die...

    I would recommend using our Relay Expansion (or at least an IC) between the Omega and the SSR. The Relay Expansion has a GPIO expander chip on it, so if something were to get fried, it would be this IC and not your Omega.



  • @Lazar-Demin Yes the GPIO 0 was plugged into the SSR 3-32V+ and the ground was plugged into the SSR -

    There was nothing connected to the SSR load side during my test.

    0_1541620996978_IMG_20181107_140221.jpg


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.