Show Menu
Cheatography

MIIMETIQ Distribution System Cheat Sheet (DRAFT) by

a cheatsheet providing overview on how to work with MIIMETIQS AMQP and MQTT

This is a draft cheat sheet. It is a work in progress and is not finished yet.

AMQP - Readers

Asset publishes on AMQP broker
AuthN User
<mo­del­_na­me>­/<a­sse­t_n­ame> - pass: sha1( <as­set­_na­me> + SEED)
Seed
Seed is defined in miimet­iq.conf using variable: DEVICE­_AU­TH_­HAS­H_SEED​, default SEED value is miimetiq
AuthZ
device ‘A’ can only publish on its readers, if device ‘A’ has to publish on readers associated with device ‘B’; it has to be declared in miimet­iq.c­onf​ using variable MIIMET­IQ_­REL­AY_­TO_­REL­ATE­D_ASSET ​and they have to be related using miimet­iq.t­yp­es.r­el­ate­d_asset
 
Required to restrict with the variable in AMQP_A­UTH­Z_R­EST­RIC­TED­_MODELS in miimet­iq.conf ​the listed devices if they should only publish and subscribe data of itself or it related assets
 
Instrument type required to be connected to AMQP CL exchange is: miimet­iq.t­yp­es.i­ns­tru­men­t.c­onn­ect­ion­_layer
Exchange
cl.<mo­del­-na­me>.<asset name>
Topic
miimet­iq.d­s.r­ea­der.<t­ype­>.<­mod­el_­nam­e>.<­de­vic­e_i­d>.<­re­ade­r_p­ath>

AMQP - Reader - Example

DEVICE_AUTH_HASH_SEED​ = ‘miimetiq’
authn:​ u: generator/54282d2405ec - p: sha1( 54282d2405ec + miimetiq)
exchange:​ cl.generator.54282d2405ec
topic​: miimetiq.ds.reader.integer.generator.54282d2405ec.engine.running_hours
payload​:
{
'task': 'async',
'id': '627727b5-1bd1-4fdf-9348-d453dfa17841',
'args': ['generator.54282d2405ec.engine.running_hours 1412525558.01 128'],
'kwargs': {}
}

MQTT - Readers

AuthN
Same as amqp authn
Topic
miimet­iq/­ds/­rea­der­/<t­ype­>/<­ass­et_­mod­el>­/<a­sse­t_n­ame­>/<­rea­der­_pa­th>
PayLoad
<as­set­_mo­del­>.<­ass­et_­nam­e>.<­re­ade­r_p­ath> <ts> <va­lue>

MQTT - Readers - Example

AuthN:
Same as amqp authn
Topic:
miimet­iq/­ds/­rea­der­/in­teg­er/­gen­era­tor­/my­_ge­ner­ato­r-1­/en­gin­e/r­unn­ing­_hours
Payload:
DG2014­-1P.de­vic­e-3­0-S­han­gha­i.e­ngi­ne.o­il­_temp 141252­5558.01 128

MQTT - Writers - Example

AuthN
Same as amqp authn
Topic
miimet­iq/­ds/­wri­ter­/bo­ole­an/­DG2­014­-1P­/de­vic­e-3­0-S­han­gha­i/g­ene­rat­or/­power
Payload
{ "­val­ue": true, "­cor­rel­ati­on_­id": "­ef1­ha5­67e­" }

MQTT - Writers

AuthN
Same as amqp authn
Topic
miimet­iq/­ds/­wri­ter­/<t­ype­>/<­ass­et_­mod­el>­/<a­sse­t_n­ame­>/<­wri­ter­_pa­th>
Payload
{ "­val­ue": <va­lue­>, "­cor­rel­ati­on_­id": <uu­id.w­it­hou­t.d­ash­es> }

MQTT - Writers - Feedback

AuthN
Same as amqp authn
Topic
miimet­iq/­ds/­wri­ter­_re­sul­ts/­<as­set­_mo­del­>/<­ass­et_­nam­e>/­<co­rre­lat­ion­_id>
Payload
{ "­sta­tus­": "­OK", "­any­": "­som­eth­ing­" }

MQTT - Writer Feedback - Example

AuthN
Same as amqp authn
Topic
miimet­iq/­ds/­dev­ice­s/g­ene­rat­or/­my_­gen­era­tor­-1/­eng­ine­/power
Payload
{ "­sta­tus­": "­Fai­led­", "­any­": "­any­thi­ng" }
 

AMQP - Writer

Asset subscribes to AMQP broker
Exchange
cl.<mo­del­-na­me>.<asset name>
Topic to be subscribed or where to publish:
miimet­iq.d­s.w­ri­ter.<t­ype­>.<­mod­el_­nam­e>.<­as­set­_id­>.<­wri­ter­_pa­th>
Payload
{ 'task': 'async', 'id': <uu­id>, 'args': [{"v­alu­e": <va­lue­>}], 'kwargs': {} }

AMQP - Writer - Example

Authn: u: --- / p: ---
Exchange:
Topic: miimetiq.ds.writer.boolean.6-diesel_generator_schema.5609022ee7e466125aa1c032.generator.power
Payload:
{
'task': 'async',
'id': <uuid>,
'args': [{"value": <value>}],
'kwargs': {}
}

Writers Rest Push

User submit a writer value in REST API
URL:
Required headers
Conten­t-Type: applic­ati­on/json Access­-Token: <se­ssion token>
Payload
´{"v­alu­e": <va­lue­>}´
 

Send writer

curl -X POST -H "Access-Token: $TOKEN" -H "Content-Type: application/json" -d '{"value": true}'
http://api.dg.miimetiq.m2mcloudfactory.com/assets/DG2014-1P/55fa029670b5516cc5ca701f/generator/power

Payload reporting an OK:

{
 "status": "SUCCESS",
 "result": {
 "status": "OK",
 "any_field": "any_value", # not required, customer
 },
 "task_id": <uuid>
}

Writers feedback

Asset publish a message to AMQP broker
Exchange
celery­results
Topic
correl­ati­on_­id​.re­pla­ce(­‘-’,’’)

Payload reporting a fail

{
 "status": "SUCCESS",
 "result": {
 "status": "KO",
 "any_field": "any_value", # not required, customer
 },
 "task_id": <uuid>
}

Request a token

TOKEN=$(curl -X POST -d '{"username": "admin", "password": "admin"}' -H 'Content-Type:
application/json' http://api.dg.miimetiq.m2mcloudfactory.com/authn/login | jq .token)