I’m getting closer to creating – what is to me – a useful wall-mounted wireless temperature sensor using the ESP8266 module.

However, one thing that I didn’t want for this system is the display to be on all the time. The blue light from the OLED isn’t that nice and I don’t really need to know the temperature at every moment.

Instead, it would be good if the display only came on when someone is trying to change the display. More specifically, it would be good if the display only came on when the rotary encoder was being used and for about 60 seconds after the last turn.

So that’s what I’ve done!

FSM

I’ve updated the VERY simple FSM to include two more states and quite a few more transitions. Below is a messy diagram showing the state, the triggers, and the transitions for the new FSM. The letters in boxes correspond to the square brackets as explained in the transitions below.

FSM_26Mar16.jpg

Diagram of FSM

States

I now have two states in this FSM: waiting & sleeping

  • waiting
    • This is when the display is on.
    • The display should stay on for 60 seconds after the last change in the rotary encoder.
    • The display will show the latest temperature and the latest desired temperature. If either of these change in this state, the screen is updated.
  • sleeping
    • This is when the display is off.
    • This state will happen 60 seconds after the last change in the rotary encoder.
    • If the encoder is changed during this state, the FSM moves to waiting.
    • If the temperature or MQTT desired temperature are updated in this state, the new values are stored, but nothing is shown on the screen. The screen will remain blank.

Triggers

The triggers for the new FSM are explained below.

  • TRIGGER_TEMPERATURE_WAIT
    • Happens every 60 seconds.
    • Causes the system to get the current temperature.
  • TRIGGER_60_SECONDS
    • Happens every 60 seconds when in the waiting state.
    • Causes the device to go from waiting to sleeping.
  • TRIGGER_ENCODER_CHANGE
    • Happens when the encoder has changed.
    • Causes the system to come out of sleep mode or:
    • Causes the system to obtain a new desired temperature.
  • TRIGGER_NEW_MQTT_DESIRED_TEMP
    • Happens when a new desired temperature is sent to the device via MQTT.

Transitions

I now have a number of new transitions are shown below. The numbers in the square brackets correspond to the square numbers on the FSM diagram.

  • transition_waiting_to_sleeping [1]
    • Turns the display off
  • transition_encoder_move_from_sleeping [2]
    • Turns the display back on
  • transition_obtain_temp_display [3]
    • Obtains the new temperature and displays it
  • transition_new_desired_temp_mqtt [4]
    • Updates the new desied temperature and displays it
  • transition_obtain_temp_display [5]
    • Takes the new temperature from the encoder and displays it
  • transition_obtain_temp [6]
    • Obtains the new temperature, but doesn’t display it
  • transition_new_desired_temp_mqtt_sleeping [7]
    • Updates the new deisred temperature, but doesn’t display it.

Outcome

The code for this is still VERY messy, but as far as I can tell, it all appears to be working well. I’ve uploaded a short video to Youtube showing the device working. I’ve changed some of the times to make it easier to see (time until going to sleep is set as 10 seconds, temperature update interval set to 5 seconds).

You can see the video here Sorry for the terrible video quality…

Next Step

My next step is to start improving the circuit used. I’m going to start designing PCB that uses the ESP-12E board. That way I won’t be relying on the NodeMCU board, but this does mean that I have to design more of the circuit myself. That shouldn’t be an issue, but the ESP-12E isn’t the most breadboard friendly device!

Advertisements