Exemple #1
0
def register_ack(request):
    result = []
    r = "FAIL"
    #thread_list = []
    if request.method == 'POST':
        print(str(request.body))
        # send Register ACK messages to /ADLINK/SEMA/Discover
        try:
            decoded = json.loads(str(request.body))
            pkt_register_ack = decoded['register_ack']
            for a in pkt_register_ack:
                pkt_model_name = a.get('model_name')
                pkt_device_id = a.get('device_id')
                pkt_ipv4 = a.get('ipv4')
                a['id'] = "register_ack"
                jstr = json.dumps(a)
                if pkt_model_name != None and pkt_device_id != None and pkt_ipv4 != None:
                    print "pkt_model_name=" + pkt_model_name + ", pkt_device_id=" + pkt_device_id + ", pkt_ipv4=" + pkt_ipv4
                    # Save Topic to db
                    pkt_device_topic = ROOT_TOPIC + \
                        clean_name(pkt_model_name) + "/" + clean_name(pkt_device_id)
                    print "pkt_device_topic = " + pkt_device_topic
                    pkt_control_topic = pkt_device_topic + CONTROL_TOPIC
                    pkt_configure_topic = pkt_device_topic + CONFIGURE_TOPIC
                    db = models.Topic(device_id=pkt_device_id, model_name=pkt_model_name,
                                      ipv4=pkt_ipv4, device_topic=pkt_device_topic, control_topic=pkt_control_topic,
                                      configure_topic=pkt_configure_topic)
                    db.save()
                    publish_single("/ADLINK/SEMA/Discover", jstr, 1, 0)

            r = "OK"
        except:
            print "register_ack error"
    #r = serializers.serialize('json', result)
    return HttpResponse(r, content_type="application/json")
Exemple #2
0
def discover(request):
    result = []
    jstr = ""
    r = "FAIL"

    print "discover"
    if request.method == 'POST':
        # post a discover message to /ADLINK/SEMA/Discover
        try:
            # print str(request.body)
            decoded = json.loads(str(request.body))
            server_name = decoded.get('server_name')
            server_ipv4 = decoded.get('server_ipv4')
            valid_from = decoded.get('valid_from')
            valid_thru = decoded.get('valid_thru')
            decoded['id'] = "discover"
            jstr = json.dumps(decoded)

            if server_name != None and server_ipv4 != None and valid_from != None and valid_thru != None:
                # Send mqtt pub
                publish_single("/ADLINK/SEMA/Discover", jstr, 2, 1)
                r = "OK"
        except:
            print "json.loads error"
    elif request.method == 'DELETE':
        # delete the discover message from /ADLINK/SEMA/Discover
        publish_single("/ADLINK/SEMA/Discover", "{}", 2, 1)
        r = "OK"

    return HttpResponse(r, content_type="application/json")
Exemple #3
0
def ping(request):
    result = []
    r = "NO DATA"

    if request.method == 'GET':
        # Send mqtt pub
        publish_single("/ADLINK/SEMA/PING", "ping", 2, 0)
        r = "OK"

    #r = serializers.serialize('json', result)
    return HttpResponse(r, content_type="application/json")