Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
atsd_serial_example add python serial reader Jan 12, 2016


connectedDevices ###Hardware & Software All sketches were tested using Arduino IDE v1.6.5, arduino uno with a wifi shield, and a DHT11 sensor.

If you do not have a shield connecting the arduino to the Internet, you can use a serial port and a simple java application that will send the data into ATSD. See atsd_serial_example.


Step 1: Download the Axibase Arduino project:
git clone https://github.com/axibase/arduino
Step 2: Modify the sketch:

Depending on which protocol you are going to use, MQTT or TCP, modify one of the following files:


To get started we suggest you first try setting up your Arduino using the TCP protocol sketch, then you can try using the MQTT sketch with bidirectional messaging.

NOTE: MQTT supports bidirectional messaging, which allows you to deliver messages to the microcontroller from the ATSD server.

Replace ssid and pass parameters with the actual ssid and password, or modify the sketch to use the ethernet shield instead of wifi shield.

char ssid[] = "ssid";           // your network SSID (name)
char pass[] = "ssidPass";       // your network password
Step 3: Generate a unique GUID for your microcontroller using the following service:

GUID generator

Step 4: Setup your entityID:

Replace entityID parameter with the generated unique GUID in the chosen sketch.

NOTE: Be sure to set a unique entityID (GUID) for each microcontroller that you are using.

String entityID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
Step 5: Upload the sketch to your device using ArduinoIDE.

##MQTT Library The sketches use modified Gaehwiller's MQTT library v1.5. This library was modified to support message length of greater than 90 characters. You can install the libraries using the following commands:

git clone https://github.com/Sild/arduino-mqtt
mv arduino-mqtt $ARDUINO_IDE_FOLDER/libraries/MQTT

There is some limitation to use message body - you can not publish message longer then 80 letter. It causing by buffer size limit. You can increase it by modifying library source code ( MQTT/src/MQTTClient.h ):

#define MQTT_BUFFER_SIZE 128 

Set MQTT_BUFFER_SIZE 256, for example.

##DHT library & sensor You can install the DHT library using Library Manager in your ArduinoIDE by typing the model name, for example "DHT11", in the search field and pressing Install, or by executing the following commands:

git clone https://github.com/adafruit/DHT-sensor-library
mv DHT-sensor-library $ARDUINO_IDE_FOLDER/libraries/DHT_sensor_library

If you are not using a DHT-sensor and a DHT-library, you should comment out the following lines in your respective sketch:

#include "DHT.h" //add DHT library
float getTemperature() {
  return dht.readTemperature();
float getHumidity() {
  return dht.readHumidity();


    String temperature = "series e:" + entityID + " m:temperature=" + (String)getTemperature();  
    Serial.println("sending row: '" + temperature + "' ...");
    String humidity = "series e:" + entityID + " m:humidity=" + (String)getHumidity();  
    Serial.println("sending row: '" + humidity + "' ...");


    String temperature = "series e:" + entityID + " m:temperature=" + (String)getTemperature();  
    Serial.println("sending row: '" + temperature + "' ...");
    String humidity = "series e:" + entityID + " m:humidity=" + (String)getHumidity();  
    Serial.println("sending row: '" + humidity + "' ...");

If you have commented out the lines as intructed above, be sure to add the correct code for your sensor's make and model in order for the device to function.

###Connecting the DHT11 Sensor Connect your DHT11 sensor to your Arduino device as displayed on the following images:

dht11 unoScheme

In the sketch, be sure to specify the right data pin (2 by default):

#define DHTPIN 2

##Test Arduino with your ATSD instance


  • To send data using MQTT, you need to install the mosquitto MQTT-broker and MQTT-clients. The following commands will install mosquitto-broker and mosquitto-client on your server:
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients

Download start_mqtt.sh script and make it executable:

wget https://raw.githubusercontent.com/axibase/arduino/master/dataTransmission/start_mqtt.sh
chmod +x start_mqtt.sh

To start data transmission from mosquitto, run start_mqtt.sh script:

./start_mqtt.sh &

This script will start mosquitto-broker and will start sending data to ATSD. We expect that mqtt-broker, mqtt-clients and ATSD are running on the same server. Otherwise you need to modify start_mqtt.sh script and set the right value of atsdServer and mqttServer:



Download and install ATSD.

  • Once ATSD is running, navigate to the Rules page located on the main menu of the ATSD UI to a create rule in the ATSD Rule Engine, that will send MQTT messages when events occur.

  • Click the Import button and select the mqttResponseRule.xml file to create the rule.

You can verify that all the fields of your Rule are completed correctly or setup the rule manually here

  • Navigate to the Portals page located under Admin on the main menu in ATSD and create a visualization portal for your Arduino data.

Copy and paste the following code, substituting the entity values with your entityID, then click SAVE.

  height-units = 1
  width-units = 1


  type = chart
  time-span = 1 hour
  step-line = false

    entity = 9aedc21d-d303-488d-9db4-78a1baed303f
    metric = temperature

    entity = 9aedc21d-d303-488d-9db4-78a1baed303f
    metric = humidity

Resulting Portal:

View an example portal in Chart Lab


Once the portal is created, it can be found in the Portals dropdown list located on the main menu in ATSD.

  • All done. Your arduino device will print an alert message to your serial monitor after each iteration.

You can monitor the data using the visualization portal that you created. Which can be found in the Portals dropdown list located on the main menu in ATSD.

###Debugging MQTT

If you connect to your mosquitto server using a subscription client:

mosquitto_sub -t '#'

you will see the following messages:

series e:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx m:millis=304.52