element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog Environment Monitoring Arduino Nano 33 IoT Integrated with IOTA (7)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ahmadradhy
  • Date Created: 12 May 2021 10:35 PM Date Created
  • Views 646 views
  • Likes 3 likes
  • Comments 0 comments
Related
Recommended

Environment Monitoring Arduino Nano 33 IoT Integrated with IOTA (7)

ahmadradhy
ahmadradhy
12 May 2021

image

 

IOT2TANGLE allows developers from the IoT community to share their integrations, providing them with I2T repositories and assistance on the IOTA Streams end. This way, we create an IoT/IOTA open encyclopedia. Share your work with the world! https://iot2tangle.io/ 

Streams-mqtt-gateway-master is source code for data streams to the tangle, you can download on https://github.com/iot2tangle/Streams-mqtt-gateway.

Setup: Fisrt, you have to download the folder

git clone https://github.com/iot2tangle/Streams-mqtt-gateway.git


Precise sensing is an IoT monitoring system to collect and measure air temperature, humidity, and pressure by using BME280 sensor, integrated with IOTA Tangle.

This project is to aim at how to use Arduino Nano 33 IoT WiFi as internet connectivity with IoT MQTT protocol standard. I wrote code in Arduino IDE and use Pubsubclient to send the data to the MQTT broker, using JSON packet data at ArduinoJson library. It has been successfully sent to raspberry Pi 3+ as an MQTT broker every 5 seconds.

Runnig the Gateway:

Run the streams-gateway:

cargo run --release

This starts the server which will forward messages from the devices to the Tangle

The Output will be something like this:

Starting.... Channel root: "47d504e1a825e142dd899dda81ff787c7cfad3b83977feec3545eaef4315c8a50000000000000000:fd93e57d937910f429cdd211" To read the messages copy the channel root into https://explorer.iot2tangle.io/ Listening for topic iot2tangle on http://localhost:1883

image

The Tech: apps infrastructure is a network sensor system consisting of the Nano 33 IoT (MCU) built-in/integrated with WiFi module as internet connectivity and raspberry 3+ as IoT edge device (MQTT-Streams) programmed in the Linux Operating System on computers, which is used to measure air temperature, humidity, and pressure on the environment monitoring system. The standard communication protocol (Machine to Machine) used is MQTT to send all of the data from sensors to the local server (MQTT-streams). Communication between edge-device raspberry, IOTA tangle network, and web-dashboard could be made remotely.

By using IOTA, the monitoring and control system is also directly connected and recorded in the cloud database. All data from the sensors connected to cloud computing is visualized in time-series data. The application process is used to manage all of the data in the database in order to access device id, location, production activity details, and local time. Real-time data of all processes can be visualized using either a mobile application or web dashboards. Streams-mqtt-gateway-master is source code for data streams to the tangle, you can download on https://github.com/iot2tangle/Streams-mqtt-gateway.

The pool server is a worker getting data from IOT2Tangle every 1 hour where the main node always performs to process the data from IoT2Tangle. https://explorer.iot2tangle.io/

image

image

image

#include <Arduino.h>

#include <SPI.h>

#include <WiFiNINA.h>

#include <Wire.h>

#include <PubSubClient.h>

#include <ArduinoJson.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_BME280.h>


void initialize_wifi();

boolean reconnect();

void initialize_sensor();

void update_data();


struct dataSense

{

  float temperature = 0.0F;

  float humidity = 0.0F;

  float pressure = 0.0F;

};

static char payload[512];

static dataSense data;

//StaticJsonDocument<256> doc;


const char ssid[] = "";

const char password[] = "";


WiFiClient net;

PubSubClient mqttClient(net);


const char mqtt_broker[] = "";

const char publish_topic[] = "iot2tangle";


#define CLIENT_ID ""

#define USERNAME ""

#define PASSWORD ""

long lastReconnectAttempt = 0;

Adafruit_BME280 bme;

long lastData = 0;


void setup() {


  Serial.begin(9600);

  pinMode(LED_BUILTIN, OUTPUT);

  initialize_sensor();

  initialize_wifi();

  mqttClient.setServer(mqtt_broker, 1883); //12143

  lastReconnectAttempt = 0;

 

}


void loop() {


  if (WiFi.status() != WL_CONNECTED)

  {

    initialize_wifi();

  }


  if (!mqttClient.connected())

  {

    long now = millis();


    if (now - lastReconnectAttempt > 5000)

    {

      lastReconnectAttempt = now;


      if (reconnect())

      {

        lastReconnectAttempt = 0;

      }

    

    }

  

  } else

  {

    mqttClient.loop();

  }


  update_data();

}


void initialize_wifi(){

  delay(100);

  WiFi.disconnect();

  Serial.println();

  Serial.print("Firmware version: ");

  Serial.println(WiFi.firmwareVersion());

  Serial.print("Connecting WiFi to: ");

  Serial.println(ssid);


  while(WiFi.status() != WL_CONNECTED)

  {

    WiFi.begin(ssid, password);

    Serial.print("Attempting WiFi connection .....");

  

    if (WiFi.status() == WL_CONNECTED)

    {

      Serial.println("WiFi connected");

      Serial.println("IP address: ");

      Serial.println(WiFi.localIP());

      Serial.println("\nWiFi RSSI: ");

      Serial.println(WiFi.RSSI());

      digitalWrite(LED_BUILTIN, HIGH);

    }


    else

    {

      Serial.print("Failed to connect to WiFi");

      Serial.println(", Try again in 5 seconds");

      digitalWrite(LED_BUILTIN, LOW);

      delay(5000);

    }

  

  }

 

}


boolean reconnect(){


  Serial.println("Attempting to connect MQTT");


  if (mqttClient.connect(CLIENT_ID, USERNAME, PASSWORD))

  {

    Serial.println("Connected to MQTT broker");

  }


  return mqttClient.connected();

}


void initialize_sensor()

{

  Wire.begin();

  unsigned status;


  status = bme.begin();


  if (!status)

  {

    Serial.println("Could not find a valid BME280.");

    while(1) delay(10);

  }

 

}


void update_data()

{

  float t = bme.readTemperature();

  float h = bme.readHumidity();

  float p = bme.readPressure()/100.0F;


  data.temperature = t;

  data.humidity = h;

  data.pressure = p;


  const size_t capacity = JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(3) + 3*JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3);

  DynamicJsonDocument doc(capacity);

  JsonArray iot2tangle = doc.createNestedArray("iot2tangle");

  JsonObject iot2tangle_0 = iot2tangle.createNestedObject();

  iot2tangle_0["sensor"] = "BME280";

  JsonArray iot2tangle_0_data = iot2tangle_0.createNestedArray("data");

  JsonObject iot2tangle_0_data_0 = iot2tangle_0_data.createNestedObject();

  iot2tangle_0_data_0["temperature"] = data.temperature;

  JsonObject iot2tangle_0_data_1 = iot2tangle_0_data.createNestedObject();

  iot2tangle_0_data_1["humidity"] = data.humidity;

  JsonObject iot2tangle_0_data_2 = iot2tangle_0_data.createNestedObject();

  iot2tangle_0_data_2["pressure"] = data.pressure;

  doc["device"] = "susukuda_device1";

  doc["timestamp"] = "";


  serializeJson(doc, payload);


  long now = millis();

  if (now - lastData > 5000)

  {

    lastData = now;

    Serial.println(payload);

    mqttClient.publish(publish_topic, payload);

  }

 

}

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube