Skip to content
Permalink
Browse files

resolv conflict

  • Loading branch information...
emrahcom committed Aug 25, 2017
1 parent 52a4494 commit b75abaae7cf0046414dd759500526e12872a3c06
@@ -6,27 +6,37 @@ Table of contents
=================

- [About](#about)
- [Demo](#demo)
- [Requirements](#requirements)
- [Installation](#installation)
- [Interfaces](#interfaces)
- [Web user interface](#web-user-interface)
- [Application programming interface (API)](#application-programming-interface)
- [Python interface](#python-interface)
- [Contact](#contact)

Demo
====
Visit our [online demo box](http://demo.taliabee.io/) to try TaliaBee.

Requirements
============
- [Raspberry Pi 3 Model B](https://www.raspberrypi.org/products/raspberry-pi-3-model-b/)
- [MedIOEx Controller Card](http://www.samm.com/en/medioex-raspberry-pi-industrial-controller-card)
- [MedIOEx Switched-Mode Power Adaptor](http://www.samm.com/en/medioex-ms-4024-switched-mode-power-adaptor-24-volt-1-5-amper-smps)
- [Raspbian Jessie](https://www.raspberrypi.org/downloads/raspbian/) (fresh installed recommended)
- [Raspbian GNU/Linux](https://www.raspberrypi.org/downloads/raspbian/) (fresh installed recommended)

Installation
============
TaliaBee supports Raspbian Jessie and Raspbian Stretch. First, install [Raspbian GNU/Linux](https://www.raspberrypi.org/downloads/raspbian/). Then login as `pi` user and run the following commands:

```bash
wget https://raw.githubusercontent.com/beyaznet/TaliaBee/master/installer/install.sh
sudo bash install.sh
```

TaliaBee is ready to go now.

Interfaces
==========

@@ -69,3 +79,7 @@ TaliaBee provides a Python interface for Pythonistas too. [Python TaliaBeeIO Mod
```

Please see [Python TaliaBeeIO Module](https://github.com/beyaznet/python-taliabeeio-module) project page for common usages.

Contact
=======
[@TaliaBeeIO](https://www.twitter.com/taliabeeio) on [Twitter](https://www.twitter.com/taliabeeio)
@@ -1,5 +1,7 @@
from flask import Flask
from app.api import api, OUTPUTS
from datetime import datetime
from subprocess import getoutput
from medioex import do_di_init, ai_init, ao_init, temp_init


@@ -10,6 +12,9 @@


# OUTPUTS referenced in app.api
cmd='grep Serial /proc/cpuinfo | cut -d: -f2 | xargs'
OUTPUTS['serial'] = getoutput(cmd)
OUTPUTS['start_timestamp'] = datetime.now().timestamp()
OUTPUTS['do'] = {i: 0 for i in range(1, 13)}
OUTPUTS['ro'] = {i: 0 for i in range(13, 17)}
OUTPUTS['ao'] = {i: 0 for i in range(1, 5)}
@@ -1,10 +1,9 @@
from flask import Blueprint, jsonify, request
from flask import Blueprint, jsonify, request, abort
from datetime import datetime
from medioex import do_write, di_read, ao_write, ai_read, temp_read
from time import sleep

api = Blueprint('api', __name__, url_prefix='/api')

ANALOG_READ_WAIT= 0.05
OUTPUTS = {}

# DIGITAL INPUT ROUTES
@@ -160,62 +159,112 @@ def ro_reset_api(pin):

@api.route('/ai/<int:pin>/read', methods=['GET'])
def ai_read_api(pin):
ss = request.args.get('start', 0.0)
se = request.args.get('end', 4095.0)
try:
ss = float(ss)
se = float(se)
except ValueError:
abort(400)

if 1 > pin or pin > 4:
return jsonify({
'status': 'ERROR',
'message': 'Analog input pins for MedIOEx must be in [1, 4]'})

sleep(ANALOG_READ_WAIT)
result = ai_read(pin)

# The line below is just a linear transformation.
#
# (nv - ns) (sv - ss)
# --------- = ---------
# (ne - ns) (se - ss)
#
# ns = normal start (0)
# ne = normal end (4095)
# nv = value got via ai_read [0, 4095] ~= [0, 4096)
# ss = scaled start (given by user)
# se = scaled end (given by user)
# sv = value demanded
sv = ss + (result - 0) * (se - ss) / (4095 - 0)

return jsonify({'status': 'OK',
'type': 'ai',
'action': 'read',
'pin': pin,
'value': result})
'start': ss,
'end': se,
'value': sv})


# ANALOG OUTPUT ROUTES

@api.route('/ao/<int:pin>/read', methods=['GET'])
def ao_read_api(pin):
ss = request.args.get('start', 0.0)
se = request.args.get('end', 4095.0)
try:
ss = float(ss)
se = float(se)
except ValueError:
abort(400)

if 1 > pin or pin > 4:
return jsonify({
'status': 'ERROR',
'message': 'Analog output pins for MedIOEx must be in [1, 4]'})
result = OUTPUTS['ao'][pin]

# Check the formula at ai_read_api before changing the line below
sv = ss + (result - 0) * (se - ss) / (4095 - 0)

return jsonify({'status': 'OK',
'type': 'ao',
'action': 'read',
'pin': pin,
'value': OUTPUTS['ao'][pin]})
'start': ss,
'end': se,
'value': sv})


@api.route('/ao/<int:pin>/write', methods=['GET'])
def ao_write_api(pin):
val = int(request.args.get('val'))
ss = request.args.get('start', 0.0)
se = request.args.get('end', 4095.0)
try:
ss = float(ss)
se = float(se)
except ValueError:
abort(400)
sv = int(request.args.get('val'))

if 1 > pin or pin > 4:
return jsonify({
'status': 'ERROR',
'message': 'Analog output pins for MedIOEx must be in [1, 4]'})
elif 0 > val or val > 4095:
elif not (ss <= sv <= se or ss >= sv >= se):
return jsonify({
'status': 'ERROR',
'message': 'Analog outputs accept between 0 and 4095.'})
'message': 'Value should be between {} and {}.'.format(ss, se)})

nv = 0 + (4095 - 0) * (sv - ss) / (se - ss)
val = nv

ao_write(pin, val)
# Check the formula at ai_read_api before changing the line below
ao_write(pin, int(nv))
OUTPUTS['ao'][pin] = val

return jsonify({'status': 'OK',
'type': 'ao',
'action': 'write',
'pin': pin,
'value': val})
'value': sv})


# TEMPERATURE

@api.route('/temperature/read', methods=['GET'])
def get_temperature():
sleep(ANALOG_READ_WAIT)
result = temp_read(1)
return jsonify({'status': 'OK',
'type': 'temperature',
@@ -257,12 +306,11 @@ def status():
for pin in range(1, 17):
inputs['di'][pin] = di_read(pin)
for pin in range(1, 5):
sleep(ANALOG_READ_WAIT)
inputs['ai'][pin] = ai_read(pin)
status.update(inputs)

sleep(ANALOG_READ_WAIT)
status['temperature'] = temp_read(1)
status['uptime'] = datetime.now().timestamp() - OUTPUTS['start_timestamp']

return jsonify({'status': 'OK',
'action': 'status',
Oops, something went wrong.

0 comments on commit b75abaa

Please sign in to comment.
You can’t perform that action at this time.