Louis SchinklerNicolas DAILLYAdrianfcaron
Published

Co'B : Connected Basket

Create a connected basketball hoop that utilizes sensors and technologies (MQTT, Flask, React) to collect, analyze, and visualize data

IntermediateWork in progress148
Co'B : Connected Basket

Things used in this project

Hardware components

Sodaq Explorer
The Sodaq Explorer is an Arduino-based development board specifically designed for Internet of Things (IoT) projects. It features a microcontroller, low-power wireless connectivity (such as LoRaWAN), and sensor interfaces. With the Sodaq Explorer, we can create custom IoT applications, collect data from sensors, communicate with other connected devices, and send data to the cloud for further analysis. It's a versatile platform for low-power IoT development.
×1
Color Sensor RGB TCS34725 Unit
M5Stack Color Sensor RGB TCS34725 Unit
×1
IR Obstacle Avoidance
×1

Software apps and online services

The Things Stack
The Things Industries The Things Stack
To collect LoRa data
Arduino IDE
Arduino IDE
To program the board

Story

Read more

Schematics

2_mvozCA2ZS2.png

A potential case for Sodaq Explorer

Electronics

Code

Flask API

Python
This code snippet sets up a MQTT message handler using the mqtt_client.on_message() decorator. When a message is received, it extracts the topic and payload from the message and decodes the payload using JSON. The decoded payload is then printed, and the message is added to a list called messages.

There is also a Flask route defined (/messages) that handles a GET request. It returns the messages list as a JSON response and clears the list. Additionally, it adds the necessary headers to enable cross-origin resource sharing (CORS). Lastly, it appends a default message of [0, 0, 0] to the messages list before sending the response.
@mqtt_client.on_message()
def handle_mqtt_message(client, userdata, message):
    data = dict(
        topic=message.topic,
        payload=message.payload.decode()
    )
    decoded_payload = json.loads(data['payload'])['uplink_message']['decoded_payload']
    print(f" message on topic: {data['topic']} with payload: {decoded_payload}")

    # Ajouter le message à la liste
    messages.clear()
    message_sent = decoded_payload['bytes']
    print(message_sent)
    messages.append(message_sent)


@app.route('/messages', methods=['GET'])
def get_messages():
    response = jsonify(messages)
    # Enable Access-Control-Allow-Origin
    response.headers.add("Access-Control-Allow-Origin", "*")

    messages.clear()

    messages.append([0, 0, 0])

    return response

Arduino RGB + IR sensor

Arduino
while(digitalRead(TRIGGER_PIN) == HIGH) {
      delay(100);
    }

    tcs.setInterrupt(false); // turn LED
    delay(50);  // takes 50ms to read
    tcs.setInterrupt(true);  // turn LED

    float red, green, blue;
    tcs.getRGB(&red, &green, &blue);

    payload[0] = (uint8_t) 1;

    // le ballon est rouge
    if (red > green && red > blue) {
      payload[1] = (uint8_t) 0;
}
    // le ballon est vert
    if (green > red && green > blue) {
      payload[1] = (uint8_t) 1;
    }

    // le ballon est bleu
    if (blue > red && blue > green) {
      payload[1] = (uint8_t) 2;
}

Credits

Louis Schinkler
1 project • 1 follower
Contact
Nicolas DAILLY
33 projects • 21 followers
Associated Professor at UniLaSalle - Amiens / Head of the Computer Network Department / Teach Computer and Telecommunication Networks
Contact
Adrian
1 project • 0 followers
Contact
fcaron
15 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.