D
Not that I see.can something be improved on the code so that the impulses arrive at the same time?
This is how my requirement looks, I hope it is understandable.Not that I see.
What are the requirements? Maybe there is a different way to implement it.
Exactly!You can measure the time on the ESP8266 board and send it to the other devices. It will be very accurate.
This idea I have already had, the problem is that I then very much of my code would have to change, but it would certainly be the best solution.You can measure the time on the ESP8266 board and send it to the other devices. It will be very accurate.
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 600
#End Region
Sub Process_Globals
Public Serial1 As Serial
Public WiFi As ESP8266WiFi
Private bc As ByteConverter
Dim MacArray(6) As Byte
Private server(2) As WiFiServerSocket
Private astream(2) As AsyncStreams
Private pinSensor As Pin
Private pin1 As D1Pins
Private contador As Long
Private codigo As Int
End Sub
Private Sub AppStart
Log("AppStart")
Serial1.Initialize(115200)
Dim Passwd As String = bc.HexFromBytes(bc.SubString2(MacAddress, 0, 4))
Log("StartAP: ", WiFi.StartAccessPoint2("fgWifi", Passwd))
Log("My AP ip: ", WiFi.AccessPointIp)
Log(Passwd)
IntiServer
End Sub
#Region "server-Subs"
Public Sub IntiServer
server(0).Initialize(51041, "Server1_NewConnection")
server(0).Listen
server(1).Initialize(51042, "Server2_NewConnection")
server(1).Listen
pinSensor.Initialize(pin1.D1, pinSensor.MODE_INPUT_PULLUP)
pinSensor.AddListener("pinSensor_StateChanged")
End Sub
Sub Server1_NewConnection (NewSocket As WiFiSocket)
Log("Server1_NewConnection=" , NewSocket.Connected)
If server(0).Socket.Connected Then
astream(0).Initialize(NewSocket.Stream, "astream_NewData", "astream1_Error")
astream(0).Write(bc.StringToBytes("OK"))
End If
End Sub
Sub Server2_NewConnection (NewSocket As WiFiSocket)
Log("Server2_NewConnection=" , NewSocket.Connected)
If server(1).Socket.Connected Then
astream(1).Initialize(NewSocket.Stream, "astream_NewData", "astream2_Error")
astream(1).Write(bc.StringToBytes("OK"))
End If
End Sub
Sub astream_NewData (Buffer() As Byte)
Dim cod As String = bc.StringFromBytes(Buffer)
codigo=cod
SendValue
End Sub
Sub astream1_Error
Log("astream1_Error")
If Not(server(0).Socket.Connected) Then
Log("server(0).Listen=", 0)
server(0).Listen
End If
End Sub
Sub astream2_Error
Log("astream2_Error")
If Not(server(1).Socket.Connected) Then
Log("server(1).Listen=", 1)
server(1).Listen
End If
End Sub
#End Region
Sub pinSensor_StateChanged (State As Boolean)
If Not(State) Then
contador=contador+1
Else
SendValue
End If
End Sub
Sub SendValue
Dim key As String
key=NumberFormat(contador*100+codigo,0,0)
If server(0).Socket.Connected Then
astream(0).Write(key).Write(",")
End If
If server(1).Socket.Connected Then
astream(1).Write(key).Write(",")
End If
End Sub
Sub MacAddress() As Byte()
RunNative("getMac", Null)
Return MacArray
End Sub
#if C
#include <ESP8266WiFi.h>
void getMac(B4R::Object* u) {
WiFi.macAddress((Byte*)b4r_main::_macarray->data);
}
#end if
#include <SoftwareSerial.h>
SoftwareSerial SSBT(7,8);
SSBT.begin(38400);
SSBT.print(pasos*100+num);
SSBT.print(",");
Sub pinSensor_StateChanged (State As Boolean)
If Not(State) Then
contador=contador+1
Else
SendValue
End If
End Sub
If Not(State) Then
contador=contador+1
SendValue ' either here form every counter add
End If
SendValue 'or here for every state change