Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
attdona committed Sep 27, 2017
1 parent a70a168 commit ea89634
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 55 deletions.
47 changes: 2 additions & 45 deletions burba/tests/nais/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*
*/

#include "bocia.h"
#include "bocia_uart.h"
#include "bocia_mqtt.h"
#include "periph/gpio.h"
#include "xtimer.h"
#include <stdio.h>
Expand Down Expand Up @@ -76,50 +77,6 @@ uint32_t handle_command(uint8_t type, Command *command) {
return sts;
}

int8_t proto_input_handler(bocia_channel_t *rd, proto_msg_t command_id,
void *obj) {

proto_msg_t ack_type = {ACK_TYPE, 1};
ack_type.dline = command_id.dline;

Ack ack = ACK__INIT;

ack.id = command_id.type;

switch (command_id.type) {
case COMMAND_TYPE: {
Command *cmd = (Command *)obj;
printf("command: %ld, seq: %ld\n", cmd->id, cmd->seq);
bocia_command(rd, cmd);
break;
}
case SECRET_TYPE: {
Secret *secret = (Secret *)obj;
set_ap_password(secret->key);
cc3200_reset();
break;
}
case CONFIG_TYPE: {
bocia_set_cfg((Config *)obj);
rd->send(rd, ack_type, &ack);
break;
}
case PROFILE_TYPE: {
Profile *profile;
profile = (Profile *)obj;
DEBUG("profile: ssid: %s - pwd: ***\n", profile->uid);
sbapi_add_profile(profile->uid, profile->pwd);
rd->send(rd, ack_type, &ack);
break;
}
default:
DEBUG("custom command [%d]\n", command_id.type);
ack.status = handle_command(command_id.type, (Command *)obj);
ack.has_status = 1;
rd->send(rd, ack_type, &ack);
}
return INPUTHANDLER_OK;
}

void connection_handler(void) {
DEBUG("try to connect ...\n");
Expand Down
22 changes: 12 additions & 10 deletions burba/tests/test_cc3200_nais.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from hbmqtt.mqtt.constants import QOS_0, QOS_1, QOS_2
import hbmqtt.broker

# import test fixtures configuration
# import firmware configuration
import tc

import time
Expand All @@ -25,7 +25,6 @@
('board ready', 'BOARD_READY')
)


def handle_event(event, uart):
if (event.name == 'BOARD_INIT'):
profile = ns.msg.Profile(
Expand All @@ -45,10 +44,7 @@ def handle_event(event, uart):
assert 0


iot.init(tc.fw_build)


async def start_borker():
async def start_broker():
config = {
'listeners': {
'default': {
Expand All @@ -74,12 +70,12 @@ def test_init_board():
# check that wlan env variables username and password are set
tc.check_test_requirements()

iot.run('nais', events=events, handler=handle_event)
iot.run('nais', tc.fw_deploy_ctx, events=events, handler=handle_event)


@pytest.mark.asyncio
async def test_add_profile():
broker = await start_borker()
broker = await start_broker()

profile = ns.msg.Profile(uid='baba', pwd='there_is_no_secret_for_me')
msg = ns.marshall(profile)
Expand All @@ -106,22 +102,25 @@ async def test_add_profile():
finally:
await cli.disconnect()
await broker.shutdown()
await asyncio.sleep(15)


@pytest.mark.asyncio
async def test_switch_led():
broker = await start_broker()

msg_on = ns.marshall(cmd.Leds(red='on'))
msg_off = ns.marshall(cmd.Leds(red='off'))

cli = mqtt.MQTTClient()
await cli.connect(tc.broker)

await cli.subscribe([('hb/{}/{}'.format(tc.network, tc.board), QOS_0)])

await cli.publish('{}/{}'.format(tc.network, tc.board), msg_on, qos=QOS_0)
await asyncio.sleep(1)
await cli.publish('{}/{}'.format(tc.network, tc.board), msg_off, qos=QOS_0)

await cli.subscribe([('hb/{}/{}'.format(tc.network, tc.board), QOS_0)])

try:
# wait for the ack
message = await cli.deliver_message(timeout=3)
Expand All @@ -131,4 +130,7 @@ async def test_switch_led():
except asyncio.TimeoutError:
assert 0
finally:
# wait before shutting down the broker, otherwise the pub packets get lost
await asyncio.sleep(1)
await cli.disconnect()
await broker.shutdown()

0 comments on commit ea89634

Please sign in to comment.