B4J Question Tipps for IoT ecosystem

Blueforcer

Well-Known Member
Licensed User
Longtime User
Im planning a IoT Solution for our Company devices.
We have lots of different devicetypes such as Pumps, Analytic modules, Motorcontrols and so on.
At the Moment all devices are connected via a Bus system to the Master.
I have developed a module (With ESP and B4R) which can be built into each device and which can handle the bus protocol. So the devices can now be controlled individually via Wifi or Internet.

Now I want to develop an IoT Server platform for it. However, I am not yet sure which basis I should use for it. Maybe MQTT, Websockets or other?
Maybe you can give me some tips for the following requirements:

  • Users have to register to the Platform
  • Each user can have multiple devices.
  • Each user can have multiple devices of the same type (e.g. Pump for Chlorine, Pump for hydrogen peroxide and so on)
  • Devices can communicate with each other (user account related). (e.g. value of sensor 1 < X --> pump 3 switch on)
  • The devices are delivered unconfigured. They only know which device type they are and which functions they have themselves. There should therefore be a way to add the devices to the user account.
As an example I only know the ecosystem of "Mi Home" of Xiaomi.
I hope I haven't forgotten anything about requirements, you are welcome to ask further questions to discuss a solution together.
Thank you
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
MQTT is a good option when you want to communicate between multiple clients. WebSockets will only allow you to communicate between the clients and the server (the server can delegate messages but it is more complicated).

I think that you have two options:
- Create a non-ui B4J app that acts as a server and communicates with the clients over MQTT.
- Create a http server with jServer library that manages all the information you need.

The MQTT broker will run on the same server.
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
MQTT was also my first Solution.
But since MQTT only communicates via Topics, I dont know how to realise the Usermanagement.
Maybe i have to combine both methods. The http Server handles the Usermanagement, while MQTT is for the devicecommunication.
Because i have to link the devices to the individual user the Topic needs a authentication part like an UUID for the User AND one for the Device.
Both Methods will be a hard way i think:)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
But since MQTT only communicates via Topics, I dont know how to realise the Usermanagement.
Hard to say without better understanding your requirements. However topics don't limit you. You can create a "server" topic that only the server listens to and send any information you like to the server (which is actually a MQTT client).
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Ok thanks. I will make some Tests now with MQTT
I will inform the community how ive done this (if it works :) )
 
Upvote 0

npsonic

Active Member
Licensed User
MQTT is simple and multiple examples can be found from forum.

MQTT was also my first Solution.
But since MQTT only communicates via Topics, I dont know how to realise the Usermanagement.
Maybe i have to combine both methods. The http Server handles the Usermanagement, while MQTT is for the devicecommunication.
Because i have to link the devices to the individual user the Topic needs a authentication part like an UUID for the User AND the Device.
Both Methods will be a hard way i think:)
Logic that I have used is
- New client goes online and will send it's designation to the specific room shared by all clients.
- Server app will response back to the client from room generated from client name and transfers RSA Public Key to client.
- Client will encrypt all messages with public key and send messages only to the room generated from it's own name.

I have developed multiple IoT applications and of course I'm not sure in which kind of environment your apps will run, but mine are used in extreme conditions.
If your app will work such conditions that power failure, connection loss, machine failure, machine drowning under the water and so on are weekly occurrences then check the list.
- Constantly keep everything saved on files or databases. Do not trust RAM
- Make sure your app can recover from every situation. Try Catch is your best friend
- Make sure your app can default to some settings that will work even if important databases or files are removed
- Make sure your app handles connection timeout correctly and will send message again if there is no response from server
- Make class that will log basically everything that your app does. When your app fails and it will fail, you have place where to check what went wrong.
- Make sure that your app can't be killed and it will start every time when machine starts.
- Your app must have capability to check that information saved on memory is valid and not corrupted due to power failure or such
 
Last edited:
Upvote 0
Top