1

I'm trying to create an IOT hub that can be controlled locally (Intranet) or from Internet. The problem I'm facing is of state synchronization. The following points depict what's happening at my local and cloud server.

  • Let's say for an example on my my connected
  • Device is at state A.
  • Local Server Shows it at state A
  • Cloud Server shows it at state A
  • Cloud Server requests the state to be changed to B
  • Device State is now B
  • Network Problem
  • Local Server Shows it at state B
  • Cloud Server shows it at state A
  • Network Problem resolved
  • Cloud Server wants it to be at state C. Thinking it is at state B (which is not and this is the problem to be solved)

q1. How can I ensure the cloud server knows which state the hub is in before issuing commands?

-- I have looked for locking mechanisms (pessimistic concurrency). but since this is happening over a network. They can be really expensive.

q2. If we can allow the cloud server to issue arbitrary commands without knowing the current state of the HUB. Then what should be the logic of conflict resolution?

-- If we want to keep a simple conflict resolution mechanism of first come first server then we will have to synchronize time over the two servers which in itself is a problem.

  • Why not just ask the local server for the current state? – user253751 Mar 2 '16 at 8:25
  • The problem is that the state on the machine changes rapidly. So every time i will ask the local server of the state i will have to implement locking so that state till i change it – Parv Sharma Mar 2 '16 at 8:45
1

q1. How can I ensure the cloud server knows which state the hub is in before issuing commands?

As you don't want to do locking over the network, then instead, you issue a larger command, which includes a qualifying condition, which the device should test and then only execute the rest of the command if the condition is true.

q2. If we can allow the cloud server to issue arbitrary commands without knowing the current state of the HUB, then what should be the logic of conflict resolution?

Generally speaking, it is desirable to give the device a higher-level goal rather than a single command. If it is a heater, for example, it would be better to give the device a temperature set point instead of an "on" command. Ideally, you'd give the device a series of set points for different times of day, and that way the device could function for a while if the network breaks. You can re-issue the series whenever you have network access and you want to change it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.