Plug lives at the heart of Phoenix's HTTP layer, and Phoenix puts Plug front and center. We interact with plugs at every step of the request life-cycle, and the core Phoenix components like endpoints, routers, and controllers are all just plugs internally. Let's jump in and find out just what makes Plug so special.
Plug is a specification for composable modules in between web applications. It is also an abstraction layer for connection adapters of different web servers. The basic idea of Plug is to unify the concept of a "connection" that we operate on. This differs from other HTTP middleware layers such as Rack, where the request and response are separated in the middleware stack.
Pretty simple, right? Let's see this function in action by adding it to our endpoint in lib/hello_web/endpoint.ex. We can plug it anywhere, so let's do it by inserting plug :introspect right before we delegate the request to the router:
Our plug simply prints information from the connection. Although our initial plug is very simple, you can do virtually anything you want inside of it. To learn about all fields available in the connection and all of the functionality associated to it, see the documentation for Plug.Conn.
To see this in action, let's write a module plug that puts the :locale key and value into the connection for downstream use in other plugs, controller actions, and our views. Put the contents below in a file named lib/hello_web/plugs/locale.ex:
In the init/1 callback, we pass a default locale to use if none is present in the params. We also use pattern matching to define multiple call/2 function heads to validate the locale in the params, and fall back to "en" if there is no match. The assign/3 is a part of the Plug.Conn module and it's how we store values in the conn data structure.
Go to :4000/ and you should see the locale exhibited. Visit :4000/?locale=fr and you should see the assign changed to "fr". Someone can use this information alongside Gettext to provide a fully internationalized web application.
Phoenix.LiveDashboard.RequestLogger - sets up the Request Logger for Phoenix LiveDashboard, this will allow you to have the option to either pass a query parameter to stream requests logs or to enable/disable a cookie that streams requests logs from your dashboard.
Plug.Parsers - parses the request body when a known parser is available. By default, this plug can handle URL-encoded, multipart and JSON content (with Jason). The request body is left untouched if the request content-type cannot be parsed.
Routes are defined inside scopes and scopes may pipe through multiple pipelines. Once a route matches, Phoenix invokes all plugs defined in all pipelines associated to that route. For example, accessing "/" will pipe through the :browser pipeline, consequently invoking all of its plugs.
By abiding by the plug contract, we turn an application request into a series of explicit transformations. It doesn't stop there. To really see how effective Plug's design is, let's imagine a scenario where we need to check a series of conditions and then either redirect or halt if a condition fails. Without plug, we would end up with something like this:
To make this all work, we converted the nested blocks of code and used halt(conn) whenever we reached a failure path. The halt(conn) functionality is essential here: it tells Plug that the next plug should not be invoked.
At the end of the day, by replacing the nested blocks of code with a flattened series of plug transformations, we are able to achieve the same functionality in a much more composable, clear, and reusable way.
I am having the exact same issue on 3 existing plugs that have worked flawlessly for a couple of years. Already did the phone update, made no difference. Is there a way to undo the last plug update from a couple of weeks ago?
I reported this issue to Wyze. It would probably help if others also reported it. You have to use the troubleshooting bot but at the end you have the opportunity to contact wyze by email. They responded in a few hours. -us/requests/new
I had the exact same issue. I ended up, throwing away my outdoor plug because I thought one side was not working and ordered a brand new one. I have multiple Outdoor plugs. I set up the new one exactly as described and updated the firmware and the exact same thing happened! Number two did not work like the plug that I threw away. I ended up having to delete the schedule and create a rule for it to come on at 5:30 in the afternoon and turn off at 9:30. I did not have to set up two rules because you were able to create an on time and an off time in one rule. This worked perfectly but I am still curious as to why my other plugs work fine and this exact outlet does not work. Hope this helps.
There must be an issue with the most recent update. I had an outdoor plug and since it had been working phenomenally I purchased a second. During the setup of the new plug, I was advised there was a firmware update available. Upon completion of the setup of the new plug and the firmware update to both neither device turns on and off appropriately based on the schedules set.
Choose from a wide range of sublime scents to get the perfect fit for each room. From the bathroom to the bedroom to the kitchen, any room can benefit from the lovely aromas provided by this simple plug-in air fresheners. Browse the full collection of plug-ins and refills at Goose Creek to find all the fragrances you need to make your house feel more like a home.
Hi all I currently own a dozen or more KP115 smart plugs dotted all around the house no issues for around 18 months until Tuesday this week when out of nowhere I could hear a clicking sound upon inspection it was coming from one of the smart plugs, unplugged it and tested it in another socket same issue tried hard reset / factory reset nothing helped, anyways on to today and again another clicking sound and you guessed it upon inspection yet another KP115 smart plug just clicking away so had to remove it.
Scary thing is the fact that they are turning on and off over and over at a very fast rate this could potentially damage whatever you have plugged in or maybe even be a fire hazzard.
@thewatcher Hi Did you manage to fix this ? I just got the same problem with my KP115 energy monitor. Constant clicking on and off whenever it is plugged in and no option to control it through the kasa app. Many thanks.
It is indeed an internal hardware failure, I no longer trust them and have unplugged all others.
I never got mine RMA I have just replaced them with a different model, not pleased with the replies I got regarding my original issues which totally put me off the tplink brand for future purchases.
I feel the customer service could be improved significantly in the future would have been nice to have got replacements but hey I have learnt from my poor experience.
@thewatcher I've just had the same thing happen to me this morning. On of my many plugs just randomly clicking on and off in quick succession. No power outages or surges have occurred, the plug doesn't feel warm or anything, it's just gone I to freakout mode. I agree it's kind of worrying and makes me feel nervous about the other plugs. I feel an amazon review coming on.
Tapo P110 .... WiFI plug has commenced continuous clicking ...... I believe a power cut may have triggered this .... Tried pressing side button continuously and as one off to re-set but no joy .... Any solution to this or is it the BIN?
I am experiencing same problem with two out of four KP115 smart plugs. It seems like a manufacturing problem. Shame really. As already mentioned in this thread, this could result in significant danger and damage, depending on what is connected to these plugs. Tp-link should seriously consider a recall before somebody sues them for substantial damages.
They all die in the same way - by getting into a loop of power cycling quickly and repeatedly. It's a pretty bad way to fail: the last one died when connected to my TV yesterday, turning it on and off (as well as my entire home cinema, thanks to CEC!) every second for I don't know how long, since I wasn't in the room until the evening. Might have been hours.
The biggest issue isn't that they fail, it's how they fail. They should just die and stay dead, that would be better. This, on the other hand, is worrying, so I'm not interested in an RMA with what sounds like a design flaw, and I'm binning them all now.
Today i just tried a factory reset as asked. Then i added it back again to the tapo app. Tried turning it off and on again, manually, then via the application. No change at all, i can hear the click sound, but the power supply doesn't change.
Back at it later, i needed to plug in my device again, so i plug the tapo in. Well, this times its off by default. So i turn it on manually, and it works. I get to my phone and try turning it off there. Works again.
thank you for sharing more case details, if you can hear a click sound the plug responds the command over interent, it should cut off power or power to the connected device, if not it's more like some hardware issue with that unit. You could observe the performance if still the same problem, i recommend checking the device warranty as suggested above.
For temporary sanitary sewer lateral plugs where the lateral will be reconnected or reused for future development the lateral shall be plugged at the property line by the owner. The permit fee will consist of a $100 non-refundable inspection fee along with a deposit of $900 for assurance of the plugging work. Following successful inspection by City Engineering of the temporary plug per the plans and permit conditions the $900 deposit will be refunded to the permit holder.
For laterals that are to be permanently plugged the lateral is to be plugged at the property line by the owner (following the same procedures as the temporary sewer plug process) and it will also be plugged at the sanitary sewer main by City Engineering using a short liner process. The permit fee for a permanent plug will consist of the same inspection and deposit fees required for a temporary plug as well as fees to cover the inspection and plugging of the lateral at the sewer main. These additional permit fees are set by the Board of Public Works and are based on the size of the sanitary sewer main (see fee table below). If after cleaning and inspection of the sanitary sewer main City Engineering determines that short liner plugging cannot be completed the Plugging Fee (Labor & Materials) will be refunded to the permit holder. Madison General Ordinance Chapter 35.02(4)(c)14)
c80f0f1006