Python Forum
Values not updating for restful call
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Values not updating for restful call
#1
Hi, I got following code to get the values from GPOI from raspberry pi then post it on restful.
Code is working but I noticed, values are not updating to the restful.

Look like value from GPOI not getting updated to moist[] on service call.

It would be good if someone can put me on correct direction.

import flask
import spidev
import time
import sys
import RPi.GPIO as GPIO
from flask import request, jsonify

# GPOI settings
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz = 1000000

def readadc(adcnum):
        r = spi.xfer2([1,8+adcnum<<4,0])
        adcout = ((r[1]&3)<<8)+r[2]
        return adcout

# server settings
app = flask.Flask(__name__)
app.config["DEBUG"] = False

# message settings
try:
        moist = [
        {'id': 0,
        'volt': readadc(0)},
        {'id': 1,
        'volt': readadc(1)},
        {'id': 2,
        'volt': readadc(2)},
        {'id': 3,
        'volt': readadc(3)}
        ]
except KeyboardInterrupt:
        GPIO.cleanup()

@app.route('/', methods=['GET'])
def home():
    return "<h1>Home</h1><p>This site is a prototype API.</p>"

# A route to return all of the available entries in our catalog.
@app.route('/moist', methods=['GET'])
def api_all():
    return jsonify(moist)


#app.run()
app.run(host="0.0.0.0", port=5050) # or host=127.0.0.1, depends on your needs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  logging values from constantly updating CLI app imvirgo 1 529 Sep-27-2023, 05:01 PM
Last Post: deanhystad
  How do loop over curl and 'put' different values in API call? onenessboy 0 1,224 Jun-05-2022, 05:24 AM
Last Post: onenessboy
  updating certain values in dict. with relation to their keys malevy 17 5,324 Nov-27-2019, 02:37 PM
Last Post: buran
  Updating dictionary values Sukumar 2 2,443 Oct-03-2018, 09:53 PM
Last Post: Sukumar
  How to call the stored values Dieselkaine 6 3,797 Jul-04-2018, 10:35 PM
Last Post: gontajones
  How to call the values at the end of a text string? Dieselkaine 2 2,966 Jul-02-2018, 08:47 PM
Last Post: Dieselkaine
  updating values in objects mercator 2 3,050 Dec-07-2017, 07:41 PM
Last Post: mercator

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020