Bottom Page

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'
Quote
#2
Please, fix the indentation of your code
Quote
#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
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Server and Network (socket) [WinError 10053] SheeppOSU 2 153 Apr-13-2019, 09:23 PM
Last Post: SheeppOSU
  Need to build a ping test for work network austina2 2 326 Mar-11-2019, 06:58 PM
Last Post: austina2
  Assistance with Python Network script cscecela 2 400 Feb-24-2019, 01:23 AM
Last Post: searching1
  Run interpreter from Network? JP_ROMANO 3 476 Nov-14-2018, 02:50 AM
Last Post: wavic
  Multiple network socket servers? MuntyScruntfundle 1 372 Nov-13-2018, 03:46 PM
Last Post: wavic
  safe output in a file for all switches in a network henry1077 0 531 Jul-26-2018, 01:05 PM
Last Post: henry1077
  Batch network configuration/ verification task using Python anonyfate 1 649 Jul-03-2018, 04:30 AM
Last Post: buran
  Sync folder over network Guybrush 3 770 May-15-2018, 09:14 AM
Last Post: wavic
  How to direct python to use a specific network adapter? ormesome 9 2,708 Nov-08-2017, 06:42 PM
Last Post: nilamo
  Type consistency cross-application via UDP to_the_sun 6 1,663 May-27-2017, 11:20 PM
Last Post: to_the_sun

Forum Jump:


Users browsing this thread: 1 Guest(s)