Python Forum
creation of an application for lora sever network
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creation of an application for lora sever network
#1
i tru to flow the floranet setup,when i want to create an application it gives me a huge error in the terminal[python 2.7//ubuntu]
import click
from floranet.util import euiString, devaddrString, intHexString, hexStringInt
from floranet.commands import version, restRequest

@click.group()
def app():
pass

@app.command()
@click.pass_context
@click.argument('appeui', nargs=1)

def show(ctx, appeui):
"""show an application, or all applications.

Args:
ctx (Context): Click context
appeui (str): Application EUI
"""
if '.' in appeui:
appeui = str(hexStringInt(str(appeui)))


# Form the url and payload
server = ctx.obj['server']
payload = {'token': ctx.obj['token']}
url = 'http://{}/api/v{}'.format((server), (version))
url += '/apps' if appeui == 'all' else '/app/{}'.format(appeui)

# Make the request
data = restRequest(server, url, 'get', payload, 200)
if data is None:
return

# Single application
if appeui != 'all':
a = data
indent = ' ' * 10
if a['appinterface_id'] == 0:
a['appinterface_id'] = '-'
if a['domain'] is None:
a['domain'] = '-'
click.echo('Application EUI: ' + euiString(a['appeui']))
click.echo('{}name: {}'.format(indent, a['name']))
click.echo('{}domain: {}'.format(indent, a['domain']))
click.echo('{}fport: {}'.format(indent, a['fport']))
click.echo('{}interface {}'.format(indent, a['appinterface_id']))
if a['appinterface_id'] != '-':
click.echo('{}Properties:'.format(indent))
properties = sorted(a['properties'].values(), key=lambda k: k['port'])
for p in properties:
click.echo('{} {} {}:{}'.format(indent, p['port'], p['name'], p['type']))
return

# All applications
click.echo('{:14}'.format('Application') + \
'{:24}'.format('AppEUI') + \
'{:15}'.format('Domain') + \
'{:6}'.format('Fport') + \
'{:10}'.format('Interface'))
for i,a in data.iteritems():
if a['appinterface_id'] == 0:
a['appinterface_id'] = '-'
if a['domain'] is None:
a['domain'] = '-'
click.echo('{:13.13}'.format(a['name']) + ' ' + \
'{:23}'.format(euiString(a['appeui'])) + ' ' + \
'{:14.14}'.format(a['domain']) + ' ' + \
'{:5.5}'.format(str(a['fport'])) + ' ' + \
'{:10}'.format(str(a['appinterface_id'])))

@app.command(context_settings=dict(
ignore_unknown_options=True, allow_extra_args=True))
@click.argument('appeui')
@click.pass_context
def add(ctx, appeui):
"""add an application.

Args:
ctx (Context): Click context
appeui (str): Application EUI string
"""
if '.' in appeui:
appeui = str(hexStringInt(str(appeui)))

# Translate kwargs to dict
args = dict(item.split('=', 1) for item in ctx.args)

# Check for required args
required = ['name', 'appnonce', 'appkey', 'fport']

missing = [item for item in required if item not in args.keys()]
if missing:
if len(missing) == 1:
click.echo("Missing argument " + missing[0])
else:
click.echo("Missing arguments: " + ' '.join(missing))
return

args['appnonce'] = int('0x' + str(args['appnonce']), 16)
args['appkey'] = hexStringInt(str(args['appkey']))

# Create the payload
server = ctx.obj['server']
payload = {'token': ctx.obj['token'], 'appeui': appeui}
payload.update(args)

# Perform a POST on /apps endpoint
url = 'http://{}/api/v{}/apps'.format((server),(version))
if restRequest(server, url, 'post', payload, 201) is None:
return

@app.command(context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True))
@click.argument('appeui')
@click.pass_context]
Error:
2019-04-18T09:50:11+0100 [twisted.web.wsgi._ErrorStream#error] [2019-04-18 09:50:11,067] ERROR in app: Exception on /api/v1.0/apps [POST] Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/Flask-1.0.2-py2.7.egg/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python2.7/dist-packages/Flask-1.0.2-py2.7.egg/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.7-py2.7.egg/flask_restful/__init__.py", line 458, in wrapper resp = resource(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/Flask-1.0.2-py2.7.egg/flask/views.py", line 88, in view return self.dispatch_request(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/Flask_RESTful-0.3.7-py2.7.egg/flask_restful/__init__.py", line 573, in dispatch_request resp = meth(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/Flask_Login-0.4.1-py2.7.egg/flask_login/utils.py", line 261, in decorated_view return func(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/crochet-1.9.0-py2.7.egg/crochet/_eventloop.py", line 510, in wrapper return eventual_result.wait(timeout) File "/usr/local/lib/python2.7/dist-packages/crochet-1.9.0-py2.7.egg/crochet/_eventloop.py", line 241, in wait result.raiseException() File "<string>", line 2, in raiseException KeyError: 'appinterface_id'
Reply
#2
Please, fix the indentation of your code
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Apr-18-2019, 09:56 AM)buran Wrote: Please, fix the indentation of your code

this is the lien of floranet setup
you will find all codes
https://github.com/Fluent-networks/flora...requisites
i know that i should put the code with indentation
Reply
#4
(Apr-18-2019, 11:02 AM)moez Wrote: i know that i should put the code with indentation
then do it. I ask for indentation of your code in the first post in this thread
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tcp sever HELP abrew132 3 4,291 May-03-2017, 03:22 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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