Iot Lab Extra Questions
Iot Lab Extra Questions
#include <stdio.h>
int main() {
int num1 = 10; // Binary: 1010
int num2 = 6; // Binary: 0110
return 0;
}
ORG 0x0000
MOV A, #25h
MOV B, #3Ah
CJNE A, B, NOT_EQUAL
SETB P1.0
SJMP END_PROGRAM
NOT_EQUAL:
CLR P1.0
END_PROGRAM:
SJMP $
END
#include <SoftwareSerial.h>
void setup() {
Serial.begin(9600); // Initialize serial communication with computer
bluetoothSerial.begin(9600); // Initialize serial communication with Bluetooth module
}
void loop() {
// Check if data is available on Bluetooth module
if (bluetoothSerial.available()) {
char receivedChar = bluetoothSerial.read(); // Read the incoming byte from Bluetooth
Serial.print("Received from Bluetooth: ");
Serial.println(receivedChar); // Print the received character to Serial Monitor
}
// Check if data is available on Serial Monitor
if (Serial.available()) {
char dataToSend = Serial.read(); // Read the incoming byte from Serial Monitor
bluetoothSerial.print(dataToSend); // Send the data to Bluetooth module
}
}
Python:
import paho.mqtt.client as mqtt
import bluetooth
def bluetooth_receive():
try:
bluetooth_socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
bluetooth_socket.connect((bluetooth_device_address, bluetooth_port))
print("Connected to Bluetooth device")
while True:
data = bluetooth_socket.recv(1024)
if len(data) > 0:
print("Received data from Bluetooth:", data.decode("utf-8"))
mqtt_client.publish(mqtt_topic, data.decode("utf-8"))
except KeyboardInterrupt:
print("Keyboard interrupt detected, closing connections")
except Exception as e:
print("Error:", str(e))
finally:
bluetooth_socket.close()
mqtt_client = mqtt.Client()
mqtt_client.on_connect = on_connect
mqtt_client.on_message = on_message
mqtt_client.connect(broker_address, broker_port)
bluetooth_receive()
// Zigbee parameters
#define PAN_ID 0xABCD // Example PAN ID
#define MY_ADDRESS 0x1234 // Example device address
#define DEST_ADDR 0x5678 // Example destination address
#define RX_PIN 2 // Pin for RX (receive) on the Zigbee module
#define TX_PIN 3 // Pin for TX (transmit) on the Zigbee module
// MQTT parameters
const char* mqtt_server = "mqtt.example.com"; // MQTT broker address
const int mqtt_port = 1883; // MQTT broker port
const char* mqtt_username = "your_username"; // MQTT username
const char* mqtt_password = "your_password"; // MQTT password
const char* mqtt_topic = "zigbee_data"; // MQTT topic
void setup() {
Serial.begin(9600);
xbee.begin(Serial);
void loop() {
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
xbee.getResponse().getZBRxResponse(rx);
payloadLength = rx.getDataLength();
for (int i = 0; i < payloadLength; i++) {
payload[i] = rx.getData(i);
}
client.publish(mqtt_topic, payload, payloadLength); // Publish Zigbee data to MQTT topic
}
}
client.loop();
}
void reconnect() {
while (!client.connected()) {
if (client.connect("arduinoClient", mqtt_username, mqtt_password)) {
client.subscribe(mqtt_topic); // Subscribe to MQTT topic
} else {
delay(5000);
}
}
}
void setup() {
Serial.begin(9600);
gsmSerial.begin(9600);
delay(1000);
sendATCommand("AT"); // Check if the GSM module is responding
sendATCommand("AT+CMGF=1"); // Set SMS text mode
}
void loop() {
// Read SMS from GSM module
String message = readSMS();
String readSMS() {
String message = "";
sendATCommand("AT+CMGL=\"REC UNREAD\""); // Read unread SMS
while (gsmSerial.available()) {
char c = gsmSerial.read();
message += c;
}
return message;
}