Software Development Insights

The demise of Major Retail Chains in the US

The number of retail chain stores closing over the past few years has dramatically increased. Yet, as of 2019, large stores announced the closing of almost 7000 stores. This is comparatively more than 2018 where 5000 stores shut down. If this continues, it could be the retail apocalypse. 

Store closing sign on business store front.

The sole reason behind this rapid closing of traditional stores is the rise of e-commerce outlets where traditional stores are no longer an attention- grabber. As mentioned in the previous article, online sellers like Amazon have made it really difficult for stores to withstand in this digital era.

Most of these stores have begun changing their sales strategies particularly focussing on digital marketing. Thus, they have now moved from brick and mortar stores to e-commerce sites. The trend these days is to do purchases online. This saves time and money for needing to visit stores. Buying products online is a more convenient method.

Apart from that, bankruptcy is another major concern because of private-equity firms like what happened to Toys R Us. Most of these private-equity companies are more likely to go bankrupt than public companies. Although these companies express that they can help to grow capital, they are silent about debt and leverage buyouts.

What happened to American Apparel?

American apparel was a major selling store since its launch in 1997. It faced a lot of sexual harassment and defamation issues costing the company $3 million as fines. In 2017, facing bankruptcy for the second time, they had to close most of their stores.

It was purchased by Gildan Activewear by the end of 2017 for $88 million. The major change is that sexual images are no longer there. The new American Apparel emphasizes more on materials and pricing to attract customers.

Toys R Us: the kids’ dream store

Toys R Us has been around for 70 years and was every child’s dream store. This company faced its doom when taken by a private equity firm in 2005. It faced an unsustainable debt and filed bankruptcy in 2017.  

April 20, 2018 San Mateo / CA / USA - Toys R Us logo and "Going out of business" announcement above the entrance to one of the locations in San Francisco bay area; customers going into the store

This decision was taken as suppliers pressurized and they liquidated remaining stores. They had to close almost 700 stores of theirs and sold the rest to Canada. Many say there might be a comeback but Toys R Us will be a fond memory for many.

Victoria’s Secret – A girl’s best friend

Parent company L Brands announced closing almost 53 Victoria’s Secret stores in 2019. They even did close 30 stores in 2018 due to bad sales. One reason was the controversial comments that the chief marketing officer spoke of transgender and plus size. 

Panoramic view of a Victoria's Secret store front

This incident outraged many and led to a reduction in sales. Apart from that, many people claim that the quality of products has dropped as well.

Abercrombie and Fitch – new  toned-down version

Abercrombie and Fitch have planned to close almost 40 stores in the USA this year 2019. They have made plans to change their marketing strategies and be more sales-oriented. Getting rid of sexual ads was another point of focus. 

They have also mentioned opening 3 flagship stores redesigning others as a part of the restructuring. Moreover, The change of infrastructure in which they have moved from dark tones to a more bright and light atmosphere is a key highlight.

GAP – shutting down rapidly

One of the most famous brands, GAP is closing doors of almost 700 stores worldwide. Its sister stores like the Banana Republic are struggling to survive as they are not performing well. 

August 20, 2019 Palo Alto / CA / USA - Gap store in Stanford Shopping Center in San Francisco bay area

They are planning to split into two and have decided to change business models to increase profit. The Old Navy will go on a separate way. This is another marketing strategy as well to increase sales.

Payless- bankruptcy victim

A few years back, Payless went into bankruptcy for the second time. Now it is finally closing doors in 2019. They are planning to close almost 2300 stores within the USA. One reason was that the shoe store only has physical stores and with the increase in online sales, store sales have gone down. 

AdobeStock_284256038_Editorial_Use_Only.jpeg

On the other hand, Just like Toys R us, private equity buyouts are very hard to bear due to an extensive amount of debt. They also began liquidation sales which went until June 2019.

Michael Kors: Restructuring

Michael Kors closed almost 100 stores in 2017. This year they will be shutting 50 stores and have stated that there could be more. This is because of the low sales that the company encountered. It has also faced great difficulty to focus on average buyers being a luxury brand. However, they have partnered with Amazon and have moved to online sales which is a positive movement.

View at Michael Kors shop. Michael Kors  is a New York City-based fashion designer widely known for designing classic American sportswear for women.

Claire’s –  The Accessory Chest overcomes Bankruptcy 

Claire’s is a very popular store for teens with an extensive amount of accessories.  However, Claire’s also sought Chapter 11 protection due to bankruptcy. It, however, eliminated its debt of $1.9 million. They also underwent restructuring and eliminated about 2000 locations. 

Gymboree – Children’s clothing 

Gymboree was another victim of bankruptcy and sought for protection under chapter 11. It was another store that was dependant on brick and mortar. It faced a lot of loss in sales that made the company face debt. It has planned to close all Gymboree and Crazy 8 stores within the US and Canada which is about 900 stores in total.

J.C. Penny – 116-year-old outlet

J.C. Penny closed about 130 stores back in 2017 due to a dip in sales and has also decided to close 18 more stores. This Giant retailer was forced to close their shops because they have been losing a huge amount of money, due to a reduction in sales. At the moment, it is a broke company and stores are out of date. There are assumptions that they have been planning to open some toy shops at their brick and mortar stores.

August 14, 2019 San Jose / CA / USA - JCPenney department store located in a mall in South San Francisco bay area

Conclusion

The list of retail stores calling it quits can go on and on. It is almost like a global epidemic that infests to every retail chain and shuts it down. The list mentioned here is just a few of them. More and more companies are facing issues either due to bankruptcy or lack of sales because of online purchases. Yet, some stores like Gucci, Luis Vuitton and Claire’s have risen from this problem and have adapted new marketing strategies.

We are living in a new world, with new channels and if you want to know how to make your retail business ready for the future, please reach out to me: bjorn.nostdahl@gunnebo.com

Debounce, Internet of Things (IoT), Microsoft Azure, Node RED, Software Development Insights

Debounce Algorithms in IoT

Working in IoT we sometimes need to handle large data streams of information, that might or might not be totally accurate. Streams might contain noise, inaccurate/unreal readings and other unwanted data.

Digital oscilloscope-1

Switch debouncing

Debouncing can be done on the hardware itself, or in software. Hardware debouncing can be done either using an S-R circuit or an R-C circuit. Two famous algorithms to do software debouncing is vertical counter and shift registers. Despite being well-known, in literature, these methods are typically presented as a code dump with little or no explanation. In this article, I will touch upon these circuits, methods and other algorithms and their use in IoT debouncing.

Understanding Switch Bounce

When the contacts of mechanical switches toggle from one position to another, these contacts bounce (or “chatter”) for a brief moment. During the first millisecond, the bounces are closely spaced and irregular, and although all of it happens in the course of milliseconds, high-speed logic will detect these bounces as genuine presses and releases.

Electrical panel. Low voltage device. Electrical equipment. Power supply. Electro substation. Power net.jpg

A button release produces bounces too, but it is common for a switch release to produce less bounce than for a switch press.

Switches usually become stable after 5-20ms depending on the quality, size and electronics of the hardware.

Hardware Debouncing

Debouncing using S-R circuits

Switch debouncing using S-R circuit is one of the earliest hardware debouncing methods. In this circuit, S-R latch avoids bounces in the circuit along with the pull-up resistor. It is still the most effective debouncing approach.

The figure below depicts a simple digital debouncing circuit which is used quite often.

1

The circuit utilizes two cross-coupled NAND gates which aim to create an S-R latch, A SPDT (Single Pole Double Throw) switch and two pull up resistors. Then the resistor produces and generates a logic ‘one’ for the gates and the Switch pulls one of the inputs to ground.

If the switch is kept in a position as  seen in the figure, the output of the upper gate is ‘1’ regardless of the input of the other gate and the one created by the bottom pull up resistor which stimulates the lower NAND gate to zero, rapidly in turn hustles back to the other gate. If the switch moves back and forth like a pendulum between the contacts and is suspended or halted for a while in neither one of the regions amidst the terminals, the latch preserves its’ state because ‘0’ from the bottom NAND gate is fed back. The switch may move between the contacts but the latch’s output assures that not in any way it would bang back and therefore, the switch is bounce free.

R-C Debouncing

Although S-R is still common, it’s bulkiness cause problems when you try to use it frequently. You can see that it uses many hardware pieces. Another drawback to using S-R circuits is SPDT switches are more expensive than SPST switches. Thus, a new approach of debouncing emerged using an R-C circuit. The basic principle behind it is to use a capacitor to filter out swift adjustments or changes in the switch signal.

The following image demonstrates a basic R-C circuit which is used for debouncing.

2

It is a simple circuit which uses two Resistors, a Capacitor, a Schmidt trigger hex inverter and an SPST switch.

  • In the event where the switch opens, the voltage across the capacitor which is initially zero begins to charge to Vcc through R1 & R2. The voltage at Vin is higher and hence, the output of the inverting Schmitt trigger is low (logic 0)
  • When the switch is closed, the capacitor discharges to zero and subsequently, the voltage at Vin is ‘0’ and output of the inverting Schmidt trigger is high (logic 1)

At the time of the bouncing condition, the capacitor will halt the voltage at Vin when it comes to either Vcc or Gnd.

You may wonder why a standard inverter is not used. There is a problem for using the standard inverter gate here. TTL defines a zero input when the applied voltage is between 0 and 0.8 and the output in certain circumstances or situations is very unpredictable or unforeseeable. Thus, we must use a Scmitt trigger hex inverter. Thereby, the output remains constant even if the inputs vary or dither and it also ensures to prevent the output from switching due to its’ hysteresis trait.

Software Debouncing

We can debounce switches using the software as well. The basic principle is still to switch signals and filter out glitches if any. The most used algorithms used for that are counters and shift registers.

Counter Method

The first approach uses a counter to time how long the switch signal has been low. If the signal has been low continuously for a set amount of time, then it is considered pressed and stable. 

Let’s see the steps in the Counter method. 

First, we set up the count value to Zero. Then set up a sampling event with a certain period, say 1 ms. You can use a timer for that. On the sample event, Do the following things.

If the switch signal is high, reset the counter variable to 0 and set the internal switch state to ‘released’. If the switch signal is low, increment the counter variable by 1 until it reaches 10. once the counter reached 10, set the internal switch state to ‘pressed’. 

Shift Register Method

Similar to that of the counter method. The only difference is that it uses a shift register. The algorithm assumes unsigned 8-bit reg value usually found in microcontrollers

First, set up the shift register variable to xFF. Set up a sampling event of period 1 ms with the help of a timer. On the sample event, Do the following things.

First, shift the variable towards MSB, the most significant bit. Set LSB, the least significant bit to the current switch value. if the shift register value is equal to 0, set internal switch state to ‘pressed’. otherwise, set internal switch state to ‘released’. 

IoT Sensor Bounce

Recently my team has been working on telemetry involving OCR decoding of License Plates. I consider data from an OCR routine, a temperature sensor or a push button the same thing and debouncing the telemetry can be done very much in the same way.

Collection of European license plates from different countries

First of all, we needed to clean up the data stream by filtering out incorrect values. Since there are not control digits on license plates, we chose to trust the result if the camera would return three similar plates within five iterations.

If you want to know more about how to debounce data streams or if you have any questions, please reach out to me: bjorn.nostdahl@gunnebo.com

 

MQTT, Protocols, Software Development Insights

MQTT for Dummies

In this article, I will be discussing one of the most trending topics in IoT. I will take you through a beginner level tutorial on MQTT which is currently the most used protocol in IOT projects. 

MQTT Message Queuing Telemetry Transport-1_low

MQTT stands for Message Queueing Telemetry Transport Protocol. To put MQTT in a nutshell, it is  “A lightweight event and message-oriented protocol allowing devices to asynchronously communicate efficiently across constrained networks to remote systems”. I know that this doesn’t really help much. So let’s try to decode that definition and understand what MQTT is and how to use it.

What is MQTT?

Again, for people who have no idea about MQTT, it is a protocol for machine-to-machine communication. It uses a publisher-subscriber model for communication. If you are from a programming background, you probably would have some knowledge about the publisher-subscriber model. Anyway, we will discuss the publisher-subscriber model and how MQTT works later in the tutorial.

MQTT over HTTP for IoT

Before going onto discuss how MQTT works, let’s first try to understand how it came to existence. MQTT came to exist as a replacement for HTTP because HTTP could not properly answer the challenges in IOT and M2M projects. Unlike web applications, IOT projects have some peculiar challenges. One of the main concerns is that IOT requires the event-driven paradigm. Some of the features of this event-driven paradigm are:

  • Emitting information one-to-many 
  • Listening to events whenever they happen 
  • Distributing minimal packets of data in huge volumes 
  • Pushing information over unreliable networks  

Some other challenges you face in an M2M application 

  • Volume (cost) of data being transmitted 
  • Power consumption 
  • Responsiveness 
  • Reliable delivery over fragile connections 
  • Security and privacy 
  • Scalability

MQTT was successfully able to cope with these challenges due to their features. 

Why MQTT is good for M2M and IoT applications

MQTT has unique features you can hardly find in other protocols, like:

  • It’s easy to implement in software as it is a lightweight protocol.
  • MQTT is based on a messaging technique. This makes it faster in data transmission compared to its alternatives.
  • It uses minimized data packets which results in low network usage.
  • Low power usage. As a result, it saves the connected device’s battery.
  • Most importantly it works on real-time which makes it ideal for IoT applications.

We learnt earlier that MQTT works through a publisher-subscriber model. In a P2S system, the publisher sends its messages to a topic. Then, every subscriber of that topic will receive the message. In MQTT, Broker handles the topic and messaging process while MQTT clients behave as publishers and subscribers.

Components of MQTT

To learn about how MQTT works, we have to understand some concepts in MQTT. The fundamental components of MQQT protocol are explained below.

Broker

The broker is a server that handles the communication and data transmission between the clients. It is responsible for the distribution, management and storage of data sent and retrieved by the clients. The broker acts like a centralized hub that regulates the message exchange. 

In the case where a broker breaks down, the whole communication process breaks down as there is no way for the clients to communicate with each other directly. Therefore, the Broker Bridging mechanism was introduced to prevent such cases and build a fail-safe broker network. 

There is a number of broker applications available on the internet including the popular ones; Mosquitto and HiveMQ or you can also use cloud-based brokers from cloud providers such as IBM or Azure.

Clients (Publisher, Subscriber)

These are basically the end-users who retrieve the data distributed by the broker. Each client is assigned a unique ID to identify themselves and the session when connected to the broker. A client could either be a publisher who publishes messages under a specific topic or a subscriber who receives messages relevant to a topic, at one time.

Message

These are the chunks of data sent and received by the clients. Each message consists of a command and a payload section. The command part determines the type of message and there are 14 message types available in MQQT.

Topic

This is the namespace or literally the topic that describes what the message is about. Each message gets assigned to a topic and clients can publish, subscribe or do both to a topic. The clients can also unsubscribe from a topic if they want to. MQTT topics are just strings with a hierarchical structure. 

Assume that there is a topic called “home/kitchen”. We call home and kitchen as levels of the topic while home being topper level topic than the kitchen. Also, topics can use wild cards such as ‘+’ and ‘#’.

Publish

This is the process of clients (Publisher) sending data to the broker under a topic be distributed among the clients (Subscriber) who have requested data from the same topic.

Subscribe

This is the process of Clients (Subscribers) receiving data specific to a topic they have previously subscribed to, from the Clients (Publishers) through the broker.

QOS: Quality of Service

Each message is given an integer value from 0 to 2 to specify the delivery mode. This is known as Quality of Service. There are three different types of QOS.

  • 0 (Fire and forget) – the message is delivered only once, acknowledgement not given, high-speed delivery method.
  • 1 (Acknowledgement) – the message is delivered once or several times until an acknowledgement is received. 
  • 2 (Synchronized) – the message is delivered only once, guaranteed delivery, comparatively slower.

Practical use of MQTT

Its time to do some practical things here and get used to dealing with the MQTT protocol. As you learnt previously, there are many MQTT clients developed for each programming language.  I will use Paho python MQTT client as I am a fan of Python and it is probably the best MQTT client out there. 

mosquitto-text-side-28

First, you need a broker to create an application with MQTT. One of the most popular MQTT brokers is Mosquitto. You can install it with the following command. 

sudo apt-get install mosquitto

We set up it to work on our localhost. By default, Mosquitto listens to port 1883. Next, install the MQTT client with pip command.

sudo apt-get install mosquitto

We setup it to work on our localhost. By default, Mosquitto listens to port 1883. Next, install the MQTT client with pip command.

pip install paho-mqtt

This command will install python MQTT client library on your machine. The core of the client library is the client class which provides all of the functions to publish messages and subscribe to topics. 

There are several important methods in Paho MQTT client class which you should know:

  • connect()
  • disconnect()
  • subscribe()
  • unsubscribe()
  • publish()

Each of these methods is associated with a callback

Publishing a message

One of the main tasks you do with MQTT is publishing messages. A simple code that publishes a message usually has 4 steps.

  • Import the paho.mqtt.client class
  • Creating a client instance with Client() constructor
  • Connecting to the server with connect() method
  • Publish messages with publish() message.
import paho.mqtt.client as mqtt

clientName = mqtt.Client("uniqueClientId)
clientName.connect("localhost",1883,60)
clientName.publish("TopicLevel1/test", "Your Message Here");
clientName.disconnect();

Most of the code is self-explaining. First, you create an instance of an MQTT client. Then you connect with the broker running on Localhost. Then the client publishes its message on “TopicLevel1/test” topic. After that, it disconnects from the broker.

Subscribing to a topic

You know that MQTT is not a one to one messaging protocol as it connects many devices. The trick here is that message from any device is assigned to a topic. Any devices that are subscribed to that topic will receive the message. Similarly, you can publish messages to Topics.

You can subscribe to a topic with subscribe() method in Client class. Subscribing to a topic has the same steps as to publishing messages. I am not going to repeat it as you can easily identify these steps from the code.

import paho.mqtt.client as mqtt

def on_connect(subscriber, userdata, flags, rc):
  subscriber.subscribe("topic/test")

def on_message(client, userdata, msg):
  if msg.payload.decode() == "Disconnect!":
    subscriber.disconnect()
    
subscriber = mqtt.Client("subscribeeId")
subscriber.connect("localhost",1883,60)

subscriber.on_connect = on_connect
subscriber.on_message = on_message

subscriber.loop_forever()

In this application, the client works as a subscriber. It subscribes to the topic to the broker which in this case, runs on localhost. Whenever it receives a message, it calls for the on_message() method. If the received message is disconnected, it immediately disconnects from the broker. This is a very simple use of subscriber method. You can write more complicated logic using the same callback functions. 

So in this article, you get a concise yet comprehensive idea about MQTT. Its’ time to move on to the conclusion to recall yourself as to what is the gist of the article.

Conclusion

MQTT is a lightweight, flexible and a simple but very efficient protocol that has a definite advantage over others when it comes to IoT and M2M solutions; considering its low bandwidth and low power consumption, response time and multiple usages. In conclusion, it could be said that MQTT is the best protocol so far when it comes to IOT development.

If you want to know more about MQTT, you can check the links below or have any questions, please reach out to me: bjorn.nostdahl@gunnebo.com

MQTT and ActiveMQ on RPI

MQTT for PIC Microcontrollers