Maker.io main logo

Getting Started with Machinechat’s JEDI One IoT Software

2020-10-05 | By ShawnHymel

License: Attribution Arduino Raspberry Pi

Machinechat’s JEDI One is an Internet of Things (IoT) service that you can run locally on your own computer and within the confines of your own network. Most IoT services require you to send sensor data to their remote servers. Running an IoT service on your own network means you can control the security of the data and you have the option of working locally without a full Internet connection. This tutorial will walk you through setting up JEDI One on a Raspberry Pi and sending data to it from an Arduino (ESP8266).

Note that JEDI One is capable of running on Windows, macOS, and various distributions of Linux. We chose the Raspberry Pi for this demonstration, as it is easy to configure and works great as a headless server on a local network. JEDI One is free to try with limitations on number of users, sensors, widgets, etc.

You can also view this tutorial in video format:

 

Required Hardware

You will need the following hardware:

Install JEDI One

Head to the Raspberry Pi product page for JEDI One (note that if you are doing this on another operating system, you can go to the JEDI One installation page for PC and Mac). Click Download, and you’ll be asked to provide your email address. Once you’ve submitted, you will receive a link to download JEDI One in your inbox.

Install Raspbian on your Raspberry Pi, and go through the configuration steps to set up your user, keyboard, and network.

Open an Internet browser on your Raspberry Pi and check your email inbox. Follow the link provided by Machinechat to download the JEDI One installation file. It should come as a .zip file. So, unzip it, and copy the mcjedi.bin file. Create a jedi folder in your home directory (/home/pi/jedi) and paste the mcjedi.bin file in there.

Download Jedi One software

In a new terminal window, enter the following commands:

Copy Code
sudo apt update
sudo apt full-upgrade

Once those are done, navigate into the jedi folder and make mcjedi.bin executable:

Copy Code
cd /home/pi/jedi
sudo chmod 777 ./mcjedi.bin

Then, you’ll want to install mcjedi.bin as a service and start it:

Copy Code
sudo ./mcjedi.bin -service install
sudo ./mcjedi.bin -service start

That’s it! JEDI One is now running on your Raspberry Pi. If you need to uninstall it, simply enter the following into a terminal:

Copy Code
sudo ./mcjedi.bin -service uninstall

Configure JEDI One

If you want to access the JEDI One software from your Pi, you can open a browser and navigate to localhost:9123. However, since this site is accessible from anywhere within your network, let’s configure it from our main computer. First, open a terminal on your Raspberry Pi and enter the following:

Copy Code
ifconfig

Copy your Pi’s WiFi IP address, as we’ll need it in the next step.

Get Raspberry Pi IP Address

On your main computer, open a browser and head to <Raspberry Pi’s IP address>:9123. Log in with the following credentials:

User ID: admin

Password: admin

From there, you’ll be asked to change the admin account’s password and set a few security questions/answers.

Change Jedi One password

Head to Users and click Add User. You can add regular users here, which do not have administrator privileges. These users can view dashboards but not edit them.

Create new user in Jedi One

Head to Data Collectors, and you should see a DefaultHTTPListener. Click on the Edit Collector button to view information about the collector.

Configure data collector in Jedi One

The default collector listens for incoming data from any IP address on the network. If you know the IP address of your sensor (or sensors), you can configure this to listen for connections from a single IP address. This helps increase security to prevent any sensor (or computer) from adding data to the server.

For this demo, we’ll leave the Listen IP as Any. Note that to send the server data, you need to do so using port 8100.

Build Sensor

Connect the BME280 sensor to the ESP8266 board using I2C. If you are using the Adafruit Feather HUZZAH, you should connect the following pins:

  • ESP8266 3.3V → BME280 3Vo
  • ESP8266 GND → BME280 GND
  • ESP8266 SCL → BME280 SCK
  • ESP8266 SDA → BME280 SDI

You should have a breadboard that looks something like this:

ESP8266 BME280 IoT sensor node

Open the Arduino IDE. Install the ESP8266 board package along with the Adafruit Sensor and Adafruit BME280 libraries.

Copy the following code to a new sketch and change ssid to your WiFi's SSID, password to your WiFi's password, and host to the IP address of your Raspberry Pi.

Copy Code
/**
* Feather HUZZAH ESP8266 Jedi One Demo
*
* Connect ESP8266 to BME280 through I2C and run this demo.
* Based on: https://support.machinechat.io/hc/en-us/articles/360050302333--30-Minutes-or-Less-Build-a-Wireless-Sensor-Network-Using-NodeMCU
*/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

// Pin settings
const int LED_PIN = LED_BUILTIN;

// Wait (milliseconds) between postings
const int DELAY = 5000;

// Network Settings
const char* ssid = "<your WiFi SSID>";
const char* password = "<your WiFi password>";

// IP address of server or Raspberry Pi running Machinechat JEDI software
// If you changed the JEDI port number, replace 8100 with the new port
const char* host = "192.168.1.204:8100";

// Globals
Adafruit_BME280 bme;

void setup() {

// Use onboard LED to convey status
pinMode(LED_PIN, OUTPUT);

// Configure serial port
Serial.begin(115200);
Serial.println();

// Initialize BME280
if (!bme.begin()) {
Serial.println("Could not find BME280 sensor, check wiring.");
while(1) {
blinkLED(1, 100); // Status code: fast blink forever is error
}
}

// Connect to WiFi
Serial.print("Connected to ");
Serial.print(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
blinkLED(1, 500); // Status code: slow blink while connecting
}
Serial.println();
Serial.println("Connected!");
}

void loop() {

float temp_c;
float humd;
float pres;
String post_data;
WiFiClient client;
HTTPClient http;
String address;
int http_code;

// Read BME280 sensor values
temp_c = bme.readTemperature();
humd = bme.readHumidity();
pres = bme.readPressure() / 100.0F;

// Print values to serial monitor
Serial.print("Temperature: ");
Serial.print(temp_c, 1);
Serial.println(" *C");
Serial.print("Humidity: ");
Serial.print(humd, 1);
Serial.println("%");
Serial.print("Pressure: ");
Serial.print(pres);
Serial.println(" hPa");

// Build a string (JSON) with data to send to JEDI. Format is:
// {
// "context": {
// "target_id" : "Sensor1"
// },
// "data": {
// "metric1" : metric_value,
// "metric2" : metric_value
// }
// }
//
// Replace metric1 with what ever data metrics that you are
// sending to JEDI. Replace metric_value with the value of
// the metric. If you have more than one sensor, set the
// target_id with the name of the sensor.
post_data = String("{\"context\":{") +
String("\"target_id\":\"BMESensorNode1\"") +
String("}, \"data\":{") +
String("\"temp_c\":") + String(temp_c) + String(", ") +
String("\"humidity\":") + String(humd) + String(", ") +
String("\"pressure\":") + String(pres) +
String(" }}");

// Send out HTTP request if WiFi is still connected
if (WiFi.status() == WL_CONNECTED) {

// Blink LED to show we're transmitting
digitalWrite(LED_PIN, LOW);

// Send data to JEDI One using HTTP POST
address = String("http://") + String(host) + String("/v1/data/mc");
http.begin(address);
http.addHeader("Content-Type", "application/json");
http_code = http.POST(post_data);

// HTTP response will be negative on error
if (http_code > 0) {

// Display HTTP response code
Serial.printf("[HTTP] POST... code: %d\n", http_code);

// Display response
if (http_code == HTTP_CODE_OK) {
const String& payload = http.getString();
Serial.print("Received payload: ");
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] POST... failed, error: %s\n",
http.errorToString(http_code).c_str());
blinkLED(3, 100); // Status code: blink LED rapidly 3 times
}

// Close connection
http.end();

// Turn off LED when transmission is done
digitalWrite(LED_PIN, HIGH);
} else {

// No WiFi connection
Serial.println("No WiFi connection");
blinkLED(5, 100); // Status code: blink LED rapidly 5 times
}

// Wait before posting again
delay(DELAY);
}

void blinkLED(int times, int wait_ms) {
for (int i = 0; i < times; i++) {
digitalWrite(LED_PIN, LOW);
delay(wait_ms);
digitalWrite(LED_PIN, HIGH);
delay(wait_ms);
}
}

Upload this to your ESP8266. Open a serial terminal, and you should see the ESP8266 sending data to the JEDI One server.

Arduino serial terminal

View Data

Back in JEDI One, with your admin account, head to Dashboards > Data View. Add a new chart, and fill out the following fields:

  • Name: Temperature
  • Chart Type: Line
  • Source: BMESensorNode1 (this is the name we gave our ESP8266 in the Arduino code)
  • Property: temp_c (the name we gave the temperature field in the JSON string)
  • Unit: C (for Celsius)
  • Refresh Interval: 5 (seconds)

Add chart to Jedi One

Click Add. You should see a line chart appear with the temperature data from your sensor. Repeat this same process to add another chart (the free version only lets you add up to 2 charts). This time, let’s add a gauge for humidity:

  • Name: Humidity
  • Chart Type: Gauge
  • Min Value: 0
  • Max Value: 100
  • Source: BMESensorNode1
  • Property: humidity
  • Unit: %
  • Refresh Interval: 5

You should see a gauge for humidity and line chart for temperature. Try carefully breathing on or touching the BME280 sensor. This should cause the humidity and temperature charts to move.

Temperature and humidity IoT data in Jedi One

Note that In Settings > Notifications, you can configure your email and SMS provider. This will let you set up automatic notifications in Rules. For example, you could build a rule that sends you an email whenever the temperature measured by the BME280 sensor rises above 50°C.

Rules and notifications in Jedi One

Head to Dashboards > System View. Click on the Background button to upload an image of your house, office, factory, farm, etc. This can be an aerial view or something like a floor plan drawing. Click the Gauge button to add a widget. Configure the widget with the following settings:

  • Min value: -20
  • Max value: 40
  • Source: BMESensorNode1
  • Property: temp_c
  • Units: C

Adding temperature gauge to floorplan in Jedi One

Click Add. Repeat the process to add another widget:

  • Min value: 0
  • Max value: 100
  • Source: BMESensorNode1
  • Property: humidity
  • Units: %

You should have 2 gauges appear on top of your image. Feel free to move them around or resize them. For example, I can move them to a particular location to show the temperature and humidity of my office.

IoT data on top of a floor plan in Jedi One

If you log out and log in with your user account, you’ll notice that regular users can view Dashboards, but they cannot modify them.

User view of floor plan and IoT data in Jedi One

Resources and Going Further

We hope this helps you get started with JEDI One on your own network! Here are some additional resources to help you on your IoT journey:

制造商零件编号 2821
ESP8266 FEATHER HUZZAH LOOSE HDR
Adafruit Industries LLC
¥121.69
Details
制造商零件编号 2652
SENSOR HUM/PRESS I2C/SPI BME280
Adafruit Industries LLC
¥121.69
Details
制造商零件编号 SC0073
SBC 1.4GHZ 4 CORE 1GB RAM
Raspberry Pi
¥284.89
Details
制造商零件编号 SC0195(9)
RASPBERRY PI 4 B 8GB
Raspberry Pi
¥610.49
Details
制造商零件编号 SC0194(9)
RASPBERRY PI 4 B 4GB
Raspberry Pi
¥447.69
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum