Fan174
Posts: 179
Joined: Tue Mar 20, 2018 6:10 am

Which type of protocol being used between PI and PC in program

Tue Nov 12, 2019 2:50 pm

Hi

Program read the data from sensor via ADC and Pi send it to database. There is one I2C protocols that communicate between PI and ADC.

Pi sending data to another PC via wifi router with internet connection. I don't understand which type of protocol being used in program when PI talk to other device like PC

Code: Select all

# Author: Tony DiCola
# License: Public Domain
# Import the ADS1x15 module.
import Adafruit_ADS1x15
import MySQLdb
import time
import datetime
import pymssql
# Create an ADS1115 ADC (16-bit) instance.
adc = Adafruit_ADS1x15.ADS1115()
# Or create an ADS1015 ADC (12-bit) instance.
#adc = Adafruit_ADS1x15.ADS1015()

# Note you can change the I2C address from its default (0x48), and/or the I2C
# bus by passing in these optional parameters:
#adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
GAIN = 1

time_sensor = time.time()
# Main loop.
sensor1 = [0]*4
sensor2 = [0]*4
sensor3 = [0]*4
sensor4 = [0]*4
for i in range(4):
         sensor1[i] = adc.start_adc(i, gain=GAIN)
         sensor2[i] = adc.start_adc(i, gain=GAIN)
         sensor3[i] = adc.start_adc(i, gain=GAIN)
         sensor4[i] = adc.start_adc(i, gain=GAIN)

connobj = pymssql.connect(server='192.168.1.240', user='jay', password='jay', database='tempdb', port='1433')
cursor = connobj.cursor()
cursor.execute('SELECT * FROM temp_table')
while True:
   for row in cursor:
        print('row = %r' % (row,))        
        print "voltage"  
        #curs=db.cursor()
        cursor.execute("""INSERT INTO temp_table(data1, data2, data3, data4) 
        values(%s,%s,%s,%s)""",(sensor1[i],sensor2[i],sensor3[i],sensor4[i]))
	connobj.commit()
        print sensor1[i]
        print sensor2[i]
        print sensor3[i]
        print sensor4[i]
	cursor.execute('SELECT * FROM temp_table')
	for row in cursor:
   	 print('row = %r' % (row,))
	time.sleep(0.5)
	
connobj.close()

DirkS
Posts: 10517
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Which type of protocol being used between PI and PC in program

Tue Nov 12, 2019 3:10 pm

Fan174 wrote:
Tue Nov 12, 2019 2:50 pm
Pi sending data to another PC via wifi router with internet connection.
What makes you think that. There is no comms with a PC in there unless I'm missing something.

User avatar
B.Goode
Posts: 10964
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Which type of protocol being used between PI and PC in program

Tue Nov 12, 2019 3:28 pm

DirkS wrote:
Tue Nov 12, 2019 3:10 pm
Fan174 wrote:
Tue Nov 12, 2019 2:50 pm
Pi sending data to another PC via wifi router with internet connection.
What makes you think that. There is no comms with a PC in there unless I'm missing something.



Maybe there is a PC running a MicroSoft SQL SERVER at 192.168.1.240? [Although pedantically a (global) Internet connection is not used to access a host with an rfc1918 private address.]


In which case the protocol may be defined by MicroSoft?



Documentation for that Python library here: http://pymssql.org/en/stable/ref/pymssql.html


Code: Select all

connobj = pymssql.connect(server='192.168.1.240', user='jay', password='jay', database='tempdb', port='1433')

User avatar
procount
Posts: 2432
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Which type of protocol being used between PI and PC in program

Tue Nov 12, 2019 3:33 pm

Not Microsoft SQl, but MySQL.

MySQL clients and servers communicate over the network using the MySQL protocol. https://dev.mysql.com/doc/dev/mysql-ser ... TOCOL.html

EDIT: Ah, could be either, I see it imports 2 libs:

Code: Select all

import MySQLdb
import pymssql
Last edited by procount on Tue Nov 12, 2019 4:21 pm, edited 1 time in total.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

User avatar
B.Goode
Posts: 10964
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Which type of protocol being used between PI and PC in program

Tue Nov 12, 2019 3:47 pm

My hunch, and that's all it is, was that the module with the connect() method, with an IP address as an argument, would be looking after the protocol used 'on the wire' to communicate with the corresponding Server. That transport might well be carrying encapsulated database manipulation commands: those might be implemented in the MySQL library. Could be turtles supported by other turtles.

I think @fan174 now has enough pointers to research how the copy-pasted script is working.

Fan174
Posts: 179
Joined: Tue Mar 20, 2018 6:10 am

Re: Which type of protocol being used between PI and PC in program

Tue Nov 12, 2019 11:08 pm

I found that Pi act like client that send data to PC running MS SQL server via TCP/IP

My understanding that if two devices are communicating they must follow the some rule of logic called as protocols

ADC to PI via I2C
Pi to Router via ?
Router to PC via ?

wifi router only use to connect two or more network

Can you tell me what I am missing

User avatar
B.Goode
Posts: 10964
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Which type of protocol being used between PI and PC in program

Tue Nov 12, 2019 11:22 pm

Fan174 wrote:
Tue Nov 12, 2019 11:08 pm
I found that Pi act like client that send data to PC running MS SQL server via TCP/IP

My understanding that if two devices are communicating they must follow the some rule of logic called as protocols

ADC to PI via I2C
Pi to Router via ?
Router to PC via ?

wifi router only use to connect two or more network

Can you tell me what I am missing


For both Question Marks in your summary the answer is The Internet Protocol.

Fan174
Posts: 179
Joined: Tue Mar 20, 2018 6:10 am

Re: Which type of protocol being used between PI and PC in program

Wed Nov 13, 2019 3:51 am

B.Goode wrote:
Tue Nov 12, 2019 11:22 pm
For both Question Marks in your summary the answer is The Internet Protocol.
You thrown me back to first question

http://ecomputernotes.com/computernetwo ... k/protocol

Types of internet protocols

• TCP/IP (Transmission Control Protocol/Internet Protocol)
• ARP (Address Resolution Protocol)
• DHCP (Dynamic Host Configuration Protocol)
• DNS (Domain Name System)
• FTP (File Transfer Protocol)

There are so many available That's why I am confused which one being used in program ?

Heater
Posts: 17141
Joined: Tue Jul 17, 2012 3:02 pm

Re: Which type of protocol being used between PI and PC in program

Wed Nov 13, 2019 6:13 am

Fan174,
There are so many available That's why I am confused which one being used in program ?
Probably all of the above are in use when your Python program is talking to an SQL data base. Except FTP.

You are confused because the answer to your question is massively huge and complicated. What you have to understand is that protocols can be stacked on top of each other. Each layer of protocol making use of the protocol below it.

Consider this web page you are reading now for a moment. This text is written in English using a the latin alphabet, a kind of communications protocol between you and me.

That text is probably represented as Unicode characters encoded as UTF-8, another kind of protocol.

To display it in your browser it is wrapped in the hyper text markup language, HTML. A protocol.

To get that page from the web server the browser uses the Hyper Text Transfer Protocol HTTP. Or the secure version HTTPS.

In order to ensure correct exchange of those bytes of the HTTP/HTML, no errors, no lost bytes, the Transfer Control Protocol is used, TCP.

To actually send and receive the packets of data involved and ensure they are routed correctly over the internet the Internet Protocol is used, IP. Hence TCP/IP.

In order for the browser to find the correct IP address for the web site the Domain Name System, DNS,is used to look up host names and get IP addresses.

In order for your Pi to get an IP address in the first place it is probably using the Dynamic Host Configuration Protocol, DNS.

In order for your router to even know your Pi is on the network it is probably using the Address Resolution Protocol, ARP.

Of course you are probably using WiFi so there is that protocol involved as well

It's protocols all the way down...

So what about the SQL in your program?

It's much like the above. Except you have SQL queries instead of HTML. You will have whatever the protocol your data base uses to exchange queries and responses instead of HTTP.

That will be layered on top of TCP/IP, ARP, DHCP, WiFi etc as outlined above.
Memory in C++ is a leaky abstraction .

User avatar
B.Goode
Posts: 10964
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Which type of protocol being used between PI and PC in program

Wed Nov 13, 2019 9:17 am

Fan174 wrote:
Wed Nov 13, 2019 3:51 am
B.Goode wrote:
Tue Nov 12, 2019 11:22 pm
For both Question Marks in your summary the answer is The Internet Protocol.
You thrown me back to first question

http://ecomputernotes.com/computernetwo ... k/protocol

Types of internet protocols

• TCP/IP (Transmission Control Protocol/Internet Protocol)
• ARP (Address Resolution Protocol)
• DHCP (Dynamic Host Configuration Protocol)
• DNS (Domain Name System)
• FTP (File Transfer Protocol)

There are so many available That's why I am confused which one being used in program ?


You asked a specific question.
Pi to Router via ?
Router to PC via ?
The specific answer is The Internet Protocol. Singular. There is only one.

(The fuller answer from @heater explains the wider picture of how programs running on the RPi and PC respectively can intercommunicate using many other protocols from the IP protocol 'suite' or 'stack'.)

billio
Posts: 71
Joined: Thu Dec 15, 2011 8:25 am
Contact: Website

Re: Which type of protocol being used between PI and PC in program

Wed Nov 13, 2019 9:08 pm

pymssql uses the Tabular Data Stream (TDS), which is an application layer protocol (i.e sits on top of the other protocols discussed above). It is used to transfer data between a database server and a client. It was initially designed and developed by Sybase Inc. for their Sybase SQL Server relational database engine in 1984, and later by Microsoft in Microsoft SQL Server. The protocol itself is provided by another package FreeTDS.

See http://www.pymssql.org/en/stable/intro.html

Return to “Python”