Introduction
Welcome to airtrik documentation. You can use the sdk in the different languages to communicate to your apps and devices created through airtrik panels.
We have language bindings in Python, Javascript, Node, C and Java! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.
Installation
For Installation of the sdks visit the corresponding github repo of the sdk and read the README.md File
Getting Started
Use the following code to connect to a specific app created:
import airtrik.iot as iot
# you have to create device inside app from panel
device = "bulb"
def onConnect():
print("Connected to network")
def onReceive(deviceId, message):
print(deviceId, message)
iot.onConnect = onConnect
iot.onReceive = onReceive
# create app in the panel to get the app key
iot.connect("__APP_KEY__")
iot.subscribe(device)
while True:
message = input("Enter the message to send to "+device)
iot.send(device, message)
// create app in the panel to get the app key
AIRTRIK_connect("__APP_KEY__")
onConnect = ()=>{
console.log("Connected")
subscribe('bulb') // device to subscribe
send('bulb', 'Handshake') // `bulb` is the device `Handshake` is the initial message
}
onReceive = (msg, deviceId)=>{
console.log(msg)
console.log(deviceId)
}
var airtrik = require("airtrik")
// create app in the panel to get the app key
client = airtrik.connect("__APP_KEY__")
client.on('connect', ()=>{
client.subscribe("bulb") // device to subscribe
console.log("Connected")
client.send("bulb", "Handshake") // `bulb` is the device `Handshake` is the initial message
})
client.on('receive', (msg, deviceId)=>{
console.log(msg, deviceId)
})
import com.airtrik.iot.Airtrik;
// Connect to the app, put this code inside your Activity class
Airtrik.connect(this, "__APP_KEY__", new Airtrik.Options() {
@Override
public void onConnect(String appName, String[] devices) {
// Print app name
System.out.println(appName);
for (int i = 0; i < devices.length; i++){
// List all devices
System.out.println(devices[i]);
}
}
@Override
public void onMessageReceive(String deviceId, String msg) {
// Print all incomming message
System.out.println(msg+" from "+deviceId);
}
@Override
public void onAppKeyError(){
System.out.println("APP KEY NOT CORRECT")
}
});
// Sending message to device
Airtrik.send("__DEVICE_ID__","__MESSAGE__");
Make sure to replace
__APP_KEY__
with your APP key.
App key are generated for every app you create on the admin panel of the airtrik website. You need to sign up to create app and get the app key.
Devices are created inside the app so after creating the app, create some devices inside the app and grab the device from there.
All devices inside the same app are connected to each other and can make communication through same app key.
Different apps are seperated from each other so they can cannot communicate with each other.
Errors
Error Code | Meaning |
---|---|
400 | Bad Request – Your request sucks |
401 | Unauthorized – Your API key is wrong |
403 | Forbidden – The device requested is hidden for administrators only |
404 | Not Found – The specified device could not be found |
405 | Method Not Allowed – You tried to access a device with an invalid method |
406 | Not Acceptable – You requested a format that isn’t json |
410 | Gone – The device requested has been removed from our servers |
418 | I’m a teapot |
429 | Too Many Requests – You’re requesting too many devices! Slow down! |
500 | Internal Server Error – We had a problem with our server. Try again later. |
503 | Service Unavailable – We’re temporarially offline for maintanance. Please try again later. |