Skip to content

A library for getting crawled data periodically into fiware

License

Notifications You must be signed in to change notification settings

scilabs-bo/fiware-crawler-lib

Repository files navigation

FIWARE Crawler Library

The fiwarecrawlerlib is a Go package that provides utility functions for regularly crawling data and creating configuration groups and devices for a FIWARE IoT-Agent UL (Ultralight). It simplifies the integration of IoT devices with FIWARE IoT Agents using the Ultralight protocol for data communication.

Installation

To use this library in your Go project, you can install it with:

go get -u github.com/scilabs-bo/fiware-crawler-lib

Usage

package main

import (
    "github.com/scilabs-bo/fiware-crawler-lib"
)

func main() {
    // Create a new instance of the crawler
    crawler := fiwarecrawlerlib.New()

    // Example: Creating a new configuration group
    configGroup := crawler.NewConfigGroup()

    // Example: Creating a new device
    device := crawler.NewDevice()

    // Example: Upserting the configuration group and device
    crawler.UpsertConfigGroup(*configGroup)
    crawler.UpsertDevice(*device)
    // Customize the Device and ConfigGroup configuration if needed
    // ...

    // Start the crawler job
    crawler.StartJob(func() {
        // Define your crawling logic here
        // ...

        // Example: Crawling data and obtaining a map of attributes
        data := map[string]interface{}{
            "temperature": 25.5,
            "humidity":    60,
        }

        // Publish the data to an MQTT broker
        crawler.PublishMqtt(data)
    })
}

Configuration

The library relies on the following environment variables for configuration:

Name Required Default Description
CRONTAB true - Specifies the cron schedule for data crawling.
IOTA_HOST true - FIWARE IoT-Agent UL host address.
IOTA_PORT true - FIWARE IoT-Agent UL port number.
SERVICE true - FIWARE service identifier.
SERVICE_PATH true - FIWARE service path.
API_KEY true - FIWARE API key for authentication.
RESOURCE false /iot/d Resource path for data storage.
DEVICE_ID true - Identifier for the IoT device.
ENTITY_TYPE true - Type of the FIWARE entity associated with the device.
LOG_LEVEL false DEBUG Log level for the library (TRACE, DEBUG, INFO, WARNING, ERROR, FATAL, PANIC).
MQTT_BROKER false mosquitto MQTT broker address for data publishing.
MQTT_PORT false 1883 MQTT broker port for data publishing.
CLIENT_ID true - MQTT client identifier.
USERNAME false - MQTT broker username (optional).
PASSWORD false - MQTT broker password (optional).

Adjust the values according to your environment and requirements.

Contributing

Feel free to contribute to this library by opening issues or pull requests. Your feedback and contributions are highly appreciated.

License

This project is licensed under the MIT License.

About

A library for getting crawled data periodically into fiware

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages