connect more input to micro from pc817 - microcontroller

How to connect more input to a microcontroller?
I have 14 optocupler pc817 (1,2,3......,14):
connect all pins 4 together from 1st set of 7th pc817 to mc(E1)
connect pin 3 from pc817 no.1 to mc(A0)
connect pin 3 from pc817 no.2 to mc(A1)
connect pin 3 from pc817 no.3 to mc(A2)
connect pin 3 from pc817 no.4 to mc(A3)
connect pin 3 from pc817 no.5 to mc(A4)
connect pin 3 from pc817 no.6 to mc(A5)
connect pin 3 from pc817 no.7 to mc(E0)
connect all pins 4 together from 2nd set of 7 pc817 to mc(E2)
connect pin 3 from pc817 no.8 to mc(A0)
connect pin 3 from pc817 no.9 to mc(A1)
connect pin 3 from pc817 no.10 to mc(A2)
connect pin 3 from pc817 no.11 to mc(A3)
connect pin 3 from pc817 no.12 to mc(A4)
connect pin 3 from pc817 no.13 to mc(A5)
connect pin 3 from pc817 no.14 to mc(E0)
See this schematic:
How does the circuit work and how to write its code?

You can look at it as a 2D matrix n times m, n sets of m optocouplers, in your case n=2 and m=7.
You can read only one set of 7 optocouplers at a time. To read both, you need in principle this sequence:
Set E1 "high" and E2 "low".
Read A0 to A5 and E0 for the first set.
Set E1 "low" and E2 "high".
Read A0 to A5 and E0 for the second set.
Now you have 14 bit values and you can process them.
This is called time division multiplexing, you have 2 time steps and 7 data bits per step.
The circuit works like this:
Only those transistors that have their collectors at "high" can conduct, if they are "on" via their respective LED. I would call them "enabled". If they are "on", the "high" level is readable on A0 to A5 and E0, respectively.
Any transistor with the collector at "low" cannot provide a "high". I would call it "disabled".
To avoid interfering feedback (or reverse) current to the "disabled" transistors, the diodes separate them.

Related

What type of encryption could be used by this smart bulb?

I want to write an app that can control my smart bulb. I've captured the bluetooth dump that the bulb's official app is sending.
I found that the data is encrypted, i sent the same command several times and the output was always different, of course the bulb did the same thing each time.
There are some examples below for reference. First 3 bytes are not important (they just increment), the remaining 17 bytes are my struggle.
080000 e6 12 f2 2c 8e 11 56 f2 4e 68 92 ad 2b 40 bd 0c d5
0a0000 e2 72 9d ec 04 aa 27 1b c6 91 4b c2 a1 a1 1d 58 c5
0c0000 06 ce 72 cf f5 c3 d7 03 e5 10 2f b3 f0 34 03 b8 53
Question 1: What kind of encrypting technique does this:
one input at sender side => several different outputs
the reciever calculates one specific result from several different inputs.
Note that the reciever in this case is a smart bulb with a probably not too sophisticated chip.
Question 2: Could it be that the input is encrypted using the actual time? The time is sent in each packet, so maybe that's how the values are always different, but still the other side can figure out the original values using the recieved time?
Typically encryption adds a random element that is sent with the message so each message is different in order to prevent replay attacks, such as you are interested in.
Given that the encrypted message is 20 bytes my guess might be CTR mode. Potential algorithms might range from AES to XTEA. But knowing the encryption methods will nit help if the bulb company did their cryptography correctly.
Nota Bene: Cryptographic security relies solely on the key being secret, not the method.

add value to column within a data frame only for a subset

I have a data frame, called APD, and I would like to assign a value to the column "Fitted_voltage", but only for a specific subset (grouped by serial_number). How do I do that?
In the following example I want to assign 150 for the Fitted_Voltage but only for the Serial_number 913009814.
Serial_number Lot Wafer Amplification Voltage Fitted_Voltage
912009913 9 912 1878 375.3 NA
912009913 9 912 1892 376.8 NA
912009913 9 912 1900 377.9 NA
812009897 8 812 3931.1 370.5 NA
812009897 8 812 3934.8 371 NA
812009897 8 812 3939.9 372.3 NA
...
...
Finally I would like to do this automatically. I fit some data points and want to assign to each serial_number the fitted result.
The process could be:
Fit via function function_to_observe and do point-wise inverse regression at a specific value of 150 for serial number 912009913:
function_to_observe(150)
This yields the result
[1] 360.6395
which shall be stored in the data frame in the column Fitted_Voltage for one single serial_number
Then the next serial_number 812009897 will be fitted and this value shall be stored for it and again and again..
I know I can add the value to the column, but not limited to the subset:
APD["Fitted_Voltage"] <- Fitted_voltage<- function_to_observe(150)
Update: According to Eric Lecoutre answer I have now:
ID<- 912009913
ID2<- 912009914
APD_result<- data.frame(Serial_Number=rep(c(ID, ID2),each=1), Fitted_Voltage=NA)
comp <- tapply(APD_result$Fitted_Voltage, APD_result$Serial_Number, function_to_observe = inverse((function(x=150) exp(exp(sum(x^0*VK[1],x^1*VK[2],x^2*VK[3],x^3*VK[4])))), 50, 375))
APD_result$Fitted_Voltage = comp[APD_result$Serial_Number]
This works very well but I need to apply some minor changes. Which are not so minor for me..
1.) The Serial_numbers have to be added automatically (given as two examples "ID, ID2")
2.) I do not get tapply to run since I removed Voltage. Sorry for not specifying this in my previous question. The voltage is not of interest, I only want Serial_number and Fitted_Voltage in the end frame, which belong to each other.
Not so clear for me what your function_to_observe does. I assume you "exploits" the set of Voltage values for a given Serial_Number.
I prepared a small function that does so having an additional argument (value).
Does the following answer your question?
df <- data.frame(Serial_Number=rep(c("a","b"),each=3),Voltage=abs(100*rnorm(6)), FittedVoltage=NA)
function_to_observe <- function(vec,value=150) {mean(vec)+value}
comp <- tapply(df$Voltage, df$Serial_Number, function_to_observe, value=150)
df$FittedVoltage = comp[df$Serial_Number]
Having as
result
Serial_Number Voltage FittedVoltage
1 a 21.01196 205.4419
2 a 37.04815 205.4419
3 a 108.26565 205.4419
4 b 121.37657 264.3040
5 b 39.92053 264.3040
6 b 181.61485 264.3040
(yeah I know fitted voltage here is totally unrelated to voltage... Just does not understand what your 150 does here)

Can I use lan wire color combination like 1=Light Orange , 2=Orange, 3=Light Blue, 4 and 5 null and 6=Blue?

Can I use lan wire color combination like 1=Light Orange , 2=Orange, 3=Light Blue, 4 and 5 null and 6=Blue intsted of 1=Light Orange , 2=Orange, 3=Light Green, 4 and 5 null and 6=Green in Lan wire connection? Would that work?
here is my lan pin connection
yes, you can use it data-flow is important, more over you can see the ISP crimping will be same as you said.just try to crimp the color pattern and check it once hope it will work.
When ever you added your desired colors to RJ45 you need to crimp the same on opposite side if you use lan wire color combination like 1=Light Orange , 2=Orange, 3=Light Blue, 4 and 5 null and 6=Blue on one end the other end should be the same as 1=Light Orange , 2=Orange, 3=Light Blue, 4 and 5 null and 6=Blue as I tried the same it worked for me try it it work for you as well

Aggregating data by two variables using R and dplyr

I am using NFL play-by-play data from the 2013 season and I am looking to measure catch success rate by Wide Receivers. Essentially, I have four variables of interest: Targeted Receiver, Pass Distance, Target and Reception. I would like to obtain a data set broken down by Targeted Receiver and Pass Distance, with Targets and Receptions summarized (just a simple count) for each of the two Targeted Receiver and Pass Distance combinations (i.e. Receiver 1 Short, Receiver 1 Long).
Thank you for your help,
CLR
First, take the table df and keep only the columns that are relevant (Targeted Receiver, Pass Distance, Target, and Reception).
df <- select(df, `Targeted Receiver`, `Pass Distance`, `Target`, `Reception`)
Then, remove the rows where there is no receiver (e.g. a running play).
df <- df[!is.na(df$`Targeted Receiver`), ]
After that, use group_by from dplyr so that your data are grouped at the Target Receiver and Pass Distance level.
grouped <- group_by(df, `Targeted Receiver`, `Pass Distance`)
Finally, use the summarise function to create the count of Target and the sum of Reception.
per_rec <- summarise(grouped, Target = n(), Reception = sum(Reception))
The data will look like this:
Targeted Receiver Pass Distance Target Reception
(chr) (chr) (int) (dbl)
1 A.J. Green Deep 50 21
2 A.J. Green Short 128 77
3 A.J. Jenkins Deep 6 2
4 A.J. Jenkins Short 11 6
5 Aaron Dobson Deep 23 6
6 Aaron Dobson Short 49 31

How to perform aggregate function two times with two different criteria to a data.table

I like to use igraph to display relation ship between Switch and the Impacted Networks as a result of problem with the switch. Since there are lots of incidents, I would like to show the top 10 switches are that most problematic and as a result impacted Networks.
df
Incident Date Switch ImpactedNetwork
123 1/1/2012 A Wireless
455 1/2/2012 B LocalLan
460 1/3/2012 A LocalLan
465 1/4/2012 A Production
etc
to assing 1 everytime an incident happens with a swithc:
df$count<-c(1)
To come up with the top 10 most problematic switches:
library(data.table)
df<-df[, total := sum(count), by = Switch]
df
Incident Date Switch ImpactedNetwork count Total
123 1/1/2012 A Wireless 1 3
455 1/2/2012 B LocalLan 1 1
460 1/3/2012 A LocalLan 1 3
465 1/4/2012 A Production 1 3
from this df, how do I get the top 10 highest incident based on Total?
Once I determine, the top ten switches, I need aggregate count of ImpactedNetwork for the top then problematic switch.
t<-aggregate(count~ImpactedNetwork+Switch, df, sum)
t
ImpactedNework Switch count
Production A 1
Wireless A 1
plot(t, layout = layout.kamada.kawai, vertex.label = V(g)$name, vertex.label.color= "darkblue", edge.arrow.size=0.9, edge.curved=T, edge.label=t$count, edge.label.color="#F900F9", edge.label.font=10,vertex.shape="rectangle",edge.color="darkgreen", main="Top 10 Problematic Switches and Impacted Network"))
The ideas is this:
calculate the most incident generated switches
calculate count of impacted network give the Switch
3.Igraph the the result.
Should I do this in two separate data frames to first calculate the most incident generated switches? And, anthor data frame to calucate the count of impacted network? Any ideas is appreciated.
df[,Total:=sum(count),by=Switch][head(order(-Total),10)][ ... etc ... ]

Resources