Giter Site home page Giter Site logo

sensit_parser's Introduction

sensit_parser

This repository contains sample script to parse data coming from a Sigfox sensit version 1.

  • sensit_parser.py can be used as a serverless function for scaleway to parse incoming MQTT data,
  • call_handle.py can be called with a '--data' to attempt parsing a payload sent by a device,
  • callback_body.json contains an example of body sent by Sigfox backend in a POST callback,
  • scw_data contains exmaple of event.json and context.json dictionnaries.

Usage as Scaleway serverless function

The current version does not push the data once parsed, it could be added in the future.

Deploying a serverless function is straigtforward.

  1. Create a Namespace
  2. Create a function and choose Public or Private
  3. Select online editor / python3
  4. Paste the code in sensit_parser.py
  5. Wait for function to be ready

API example below are all using the fr-par region

Check function availability

Status of the function can be assessed in the GUI or via the API. For the API, you need to created credentials for the Organization. The API Secret can then be used as token for the API.

# Check function status with API
curl -X GET --header "x-auth-token: $SCW_TOKEN" https://api.scaleway.com/functions/v1alpha2/regions/fr-par/functions/

Call a public serverless function

A public function can simply be called via its endpoint.

# Test a public function
curl -X POST -d "@body.json" -H "Content-Type: application/json"  <endpoint>

Call a private serverless function

Private function can be called when authentified with a dedicated token. This token can be generated with the API and the function id.

# Retrieve the function ID
curl --silent  -X GET --header "x-auth-token: $SCW_TOKEN"  "https://api.scaleway.com/functions/v1alpha2/regions/fr-par/functions" | jq ".functions[]"
# Generate a token using the 'id' field of the function we want to call
curl --silent  -X GET --header "x-auth-token: $SCW_TOKEN"  "https://api.scaleway.com/functions/v1alpha2/regions/fr-par/jwt/issue?function_id=<function_id>" | jq "."
# Call the function and pass the generated token
curl -X POST -d "@callback_body.json" -H "SCW_FUNCTIONS_TOKEN: $SCW_FUNCTION_TOKEN" <endpoint>

Parse data sent to an IoT Hub MQTT broker

Using scaleway APIs or scaleway cli, you can retrieve your IoT Hub information and the name of the devices. The secret for the devices is also required depending on the method used to publish

scw iot device list

A more advanced description is available in Triggering functions from IoT Hub messages

Subscribe to a topic with mosquitto

# Verbose option will display the topic name along with the message, -t # displays all topics
mosquitto_sub -h iot.fr-par.scw.cloud -i <device id> -t # -v

Publish a message with mosquitto

mosquitto_pub -i <device id> -h iot.fr-par.scw.cloud -t <topic/subtopic> -d <data>

Publish a message with curl

Message will be received if you subscribe to the topic.

curl -X POST -d <data> -H "x-secret:<device secret>" -H "x-topic:<topic/subtopic>" <url>

Route an MQTT message to a serverless function

In the IoT hub, define a route to send your messages.

sensit_parser's People

Contributors

lionelbertaux avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.