Integrating Favoriot’s IoT platform into CNC machine automation enhances real-time monitoring and operational efficiency. Here’s a comprehensive guide to implementing this solution:
1. Overview
This system utilizes an ESP32 microcontroller to gather vibration and temperature data from CNC machines. The collected data is transmitted to the Favoriot IoT Platform via the MQTT protocol, enabling real-time monitoring and automated notifications when operational parameters deviate from predefined thresholds.
2. Required Components
- ESP32: A microcontroller equipped with Wi-Fi and MQTT capabilities.
- Vibration Sensor (e.g., ADXL345 or SW-420): For detecting machine vibrations.
- Temperature Sensor (e.g., DS18B20 or DHT22): For monitoring the machine’s operating temperature.
- Favoriot IoT Platform: Middleware designed for managing IoT data.
3. Setting Up the Favoriot IoT Platform
Step 1: Register and Create a Device
- Sign Up: Create an account on the Favoriot platform.
- Create a New Device:
- Navigate to the Devices section and select Add Device.
- Provide a Device ID and Device Name.
- Note the Device Access Token, which will serve as the username and password in MQTT configurations.
Step 2: Configure MQTT on Favoriot
| Parameter | Value |
|---|---|
| Broker URL | mqtt.favoriot.com |
| Port | 1883 (or 8883 for TLS/SSL connections) |
| Username & Password | Device Access Token |
| Client ID | Any unique identifier |
| Publish Topic | {device-access-token}/v2/streams |
| Subscribe Topic | {device-access-token}/v2/streams/status |
*Replace {device-access-token} with your specific device access token.
4. Programming the ESP32
Step 1: Establish Wi-Fi and MQTT Connections
The following code connects the ESP32 to a Wi-Fi network and the Favoriot MQTT broker:
#include <WiFi.h>
#include <PubSubClient.h>
// Wi-Fi credentials
const char* ssid = "Your_WiFi_Name";
const char* password = "Your_WiFi_Password";
// MQTT Broker Settings
const char* mqtt_server = "mqtt.favoriot.com";
const int mqtt_port = 1883;
const char* mqtt_user = "Device_Access_Token";
const char* mqtt_password = "Device_Access_Token";
// Initialize Wi-Fi and MQTT client
WiFiClient espClient;
PubSubClient client(espClient);
void setup_wifi() {
delay(10);
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nWi-Fi Connected!");
}
void reconnect() {
while (!client.connected()) {
Serial.print("Connecting to MQTT...");
if (client.connect("ESP32Client", mqtt_user, mqtt_password)) {
Serial.println("Connected!");
} else {
Serial.print("Failed, error code: ");
Serial.println(client.state());
delay(2000);
}
}
}
void setup() {
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, mqtt_port);
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
}
Step 2: Read Sensor Data
This code captures data from both temperature and vibration sensors:
#include <Wire.h>
#include <Adafruit_ADXL345_U.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin for DS18B20 temperature sensor
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Initialize ADXL345 vibration sensor
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
void setup() {
Serial.begin(115200);
if (!accel.begin()) {
Serial.println("Vibration sensor not detected!");
while (1);
}
sensors.begin();
}
void loop() {
// Read temperature
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
// Read vibration
sensors_event_t event;
accel.getEvent(&event);
float vibration = event.acceleration.x;
Serial.print("Temperature: "); Serial.print(temperature); Serial.print("°C, ");
Serial.print("Vibration: "); Serial.print(vibration); Serial.println(" m/s²");
delay(2000);
}
Step 3: Transmit Data to Favoriot via MQTT
This segment sends the sensor data to the Favoriot platform:
void send_data(float temperature, float vibration) {
char payload[200];
sprintf(payload, "{\"device_developer_id\":\"Device_Developer_ID\", \"data\":{\"temperature\":%.2f, \"vibration\":%.2f}}", temperature, vibration);
client.publish("Device_Access_Token/v2/streams", payload);
Serial.println("Data sent to Favoriot!");
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
// Read sensor data
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
sensors_event_t event;
accel.getEvent(&event);
float vibration = event.acceleration.x;
// Send data to Favoriot
send_data(temperature, vibration);
delay(5000);
}
5. Configuring the Favoriot Dashboard
- Access the Dashboard: Log in to your Favoriot account and navigate to the dashboard section.
- Add Widgets:
- Line Chart: To visualize temperature and vibration trends over time.
- Gauge Meter: For real-time temperature readings.
- Text Notification: To display alerts when thresholds are breached.
6. Implementing Automated Alerts Using RPC Rules
Step 1: Creating an RPC Rule in Favoriot
Favoriot provides RPC Rule Automation to send notifications when sensor readings exceed predefined thresholds.
- Navigate to Automation → Rules in the Favoriot Dashboard.
- Create a New Rule:
- Define Rule Name and Description to specify its purpose.
- Select the Device (
cnc_machine_01).
- Set Threshold Conditions:
- Temperature > 70°C → Trigger an alert.
- Vibration > 10 m/s² → Trigger an alert.
- Define the Action:
- Send an email alert to the responsible team.
- Trigger a Telegram notification.
- Activate an external system using Favoriot’s RPC commands.
7. Sending Alerts via Telegram
To send a notification to a Telegram group when a machine exceeds the safe operating limits, use the following Python script:
import requests
TOKEN = "YOUR_TELEGRAM_BOT_TOKEN"
CHAT_ID = "YOUR_TELEGRAM_CHAT_ID"
MESSAGE = "⚠️ Warning! CNC machine experiencing abnormal temperature/vibration levels."
url = f"https://api.telegram.org/bot{TOKEN}/sendMessage"
data = {"chat_id": CHAT_ID, "text": MESSAGE}
requests.post(url, data=data)
Step 2: Integrating Telegram Alerts into Favoriot
- Navigate to Automation → Rules.
- Set an Action: When temperature or vibration crosses the threshold, configure Favoriot to send a Webhook Request.
- Enter the Telegram API URL: Use the API format in the webhook request:
-
https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={CHAT_ID}&text={MESSAGE} -
- Save and Enable the Rule.
8. Advantages of Using Favoriot for CNC Machine Monitoring
🔹 Real-time Monitoring – Continuous machine health tracking via IoT sensors.
🔹 Automated Alerts – Immediate notifications when thresholds are exceeded.
🔹 Cloud-based Storage – Secure data storage for analytics and historical reference.
🔹 Scalability – Easily expandable to monitor multiple CNC machines simultaneously.
🔹 Remote Access – Engineers can monitor and manage machine conditions from anywhere.
9. Future Enhancements
This system can be further improved with:
✅ Predictive Maintenance – Predict failures using AI/ML models on Favoriot data.
✅ Integration with PLCs – Automate CNC shutdown if extreme conditions are detected.
✅ Dashboard Customization – More advanced widgets and visual analytics.
✅ SMS Alerts – Notify maintenance teams via SMS, emails, and Telegram.
10. Conclusion
By integrating ESP32 with Favoriot’s IoT platform, manufacturers can establish an advanced, automated CNC machine monitoring system. The MQTT-based architecture ensures real-time data transmission, while Favoriot’s automation and RPC rule engine provide instant alerts when operational anomalies occur. This reduces downtime, prevents failures, and improves overall factory efficiency.
Ready to build your own CNC IoT monitoring system with Favoriot? Start today!
[Disclaimer: This article provides a step-by-step guide. The source code may need adjustments to fit the final project design.]
![[Tutorial] : CNC Machine Automation dengan IoT Monitoring](https://iotworld.co/wp-content/uploads/2025/03/DALL·E-2025-03-16-13.24.25-A-high-tech-factory-floor-with-IoT-sensors-installed-on-CNC-machines.-A-digital-dashboard-in-the-background-displays-real-time-temperature-and-vibrati.webp)





Leave a Reply