How does a sensor data move from physical layer to application layer

I have used Arduino IDE to program a IOT gateway using ESP32 and W5500 ethernet module to use them as a ethernet webserver.

I wanted to know for educational purpose, I know that sensor belong to physical layer of the OSI model. If I have to feed sensor data to webserver how would the sensor data flow in the OSI model? Would it have to go through network layer and other intermediate layers between physical layer and application layer where webserver software resides or is it like a direct interface between physical layer(sensor) and application layer(webserver) from OSI model point of view.

Well, I don't know if I've got exactly what you mean, but IMO that sensor data acquisition is outside OSI.

Giving the sensor is connected a local electrical interface (like I2C, SPI... You haven't specified) and the ESP32 reads this sensor data using peripheral drivers, it is not part of the OSI model, this is local hardware data acquisition.

The OSI layers come into play only when a network client is requesting a page containing the values. I don't know if this is the kind of answer you were looking for.

I have been a software guy for over 60 years, and although I have heard OSI mentioned a few times in my career, I don't really know what it is, and it has never been top of mind during a long career of systems building and consulting. If you want to know more, may I suggest the following Wikipedia article?
https://en.wikipedia.org/wiki/OSI_model

A web server is an application that "talks" at layer 7 using HTTP, while a button is a sensor that "talks" at layer 1 using electrical voltage. What about the layers in between? They're simply virtual — not implemented, and there's no need to define them. If the sensor uses a serial interface, the serial protocol can be considered its layer 2.

Same here, except 50 years. A lot of that time was spent on comms (TCP etc, serial, I2C, 1553B, to mention just a few). I wonder if it's something a little academic that gets taught to students, but not used by hands on engineers?

I believe I was introduced to it in a networking course (late 70's), but as a designer and coder, I never found it necessary to apply that knowledge. I am sure there was a (good) reason to teach it, but I have no idea why.
A quick google tells me it's a set of standards and protocols.

I would say that the OSI stack is more of a conceptual separation of responsibilities. Ideally, each layer should handle a single task, regardless of how the other layers are implemented. This separation promotes modularity, protocol development, and greater interoperability between different systems. In practice, however, a real implementation may not be so strict, and entire layers may be missing or implicit.

First of all, the "OSI model", while conceptually useful, is rarely completely and exactly implemented in modern systems.
You get stuff like:

  1. Physical layer: easy: Ethernet signaling
  2. Link layer: Still Easy: Ethernet MAC format
  3. Network: IP, probably.
  4. Transport: TCP
  5. Session: oh wait, that's sort of TCP too.
  6. Presentation: oh, you know, one of many. HTML, JSON, XML, ASN.1...
  7. Application: HTTP, maybe? Or is that presentation or even Session? Maybe all the way up to the Browser?

Actually implementing strict layers gets messy and quite inefficient.


I think your problem understanding this is that you basically have TWO instances where you might apply the OSI model.
The first happens getting your sensor data into the computer. The actual data isn't really part of the model (the layers are for COMMUNICATIONS), but you'll have something like I2C as the Physical and data link layers, and then some mishmash of the other 5 layers to interpret the I2C messages and exatract the actual data values of your sensor.

At that point, you have "pure data" in your computer. Stop.

Then the usual messy 7-layers to get that data through your webserver to your browser/etc.

At least, that's how I would think about it. Your question sounds a bit like a class homework question; if it is, I wouldn't be very confident that my answer matches what your teacher wants to hear. (maybe it would be convincing anyway? Who knows!)