I'm using this library GitHub - sandeepmistry/arduino-LoRa: An Arduino library for sending and receiving data using LoRa radios., but you can also download it directly from the Arduino IDE since it is in there as well.
I've already tested it with one of the examples without modifying anything and then it works perfectly, so something is wrong about my code. (one of the 2 ESP32 boards refuses to send a responds for some reason, even tho it did receive the message and detected the command and also triggered the code that sends a response. I'm not sure if it is the ESP32 board that receives has a issue or the ESP32 board that sends)
oh and the code for the VB application is:
Imports System.Net.Sockets
Imports System.Threading
Imports System.IO
Public Class Form1
Dim tcpClient As New System.Net.Sockets.TcpClient()
Dim ListenerThread As New Thread(New ThreadStart(AddressOf Listening))
Dim message As String = ""
Dim CharRead As String = ""
Dim RSSIString As String = ""
Dim RSSINum As Integer
Dim RSSIPercentage As Integer
Dim LoRaConnected As Boolean = False
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
tmrCheckConnection.Enabled = True
tmrUpdateForm.Enabled = True
tcpClient.Connect(TextBox1.Text, 8000)
ListenerThread.Start()
End Sub
Private Sub tmrCheckConnection_Tick(sender As Object, e As EventArgs) Handles tmrCheckConnection.Tick
Label1.Text = "Connected: " & tcpClient.Connected.ToString
If tcpClient.Connected = True Then
Dim Writer As New StreamWriter(tcpClient.GetStream())
Writer.Write("GET_STATUS")
Writer.Flush()
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
tcpClient.Close()
End Sub
Private Sub tmrCheckIncomingData_Tick(sender As Object, e As EventArgs) Handles tmrUpdateForm.Tick
If LoRaConnected = True Then
If RSSIPercentage > 75 Then
Label2.Text = "Connection: Good"
Label10.Text = RSSIPercentage.ToString & "%"
ProgressBar1.Value = RSSIPercentage
ElseIf RSSIPercentage > 20 Then
Label2.Text = "Connection: Medium"
Label10.Text = RSSIPercentage.ToString & "%"
ProgressBar1.Value = RSSIPercentage
ElseIf RSSIPercentage < 21 And RSSIPercentage > 0 Then
Label2.Text = "Connection: Weak"
Label10.Text = RSSIPercentage.ToString & "%"
ProgressBar1.Value = RSSIPercentage
Else
Label2.Text = "Connection: Very low"
Label10.Text = "N/A"
ProgressBar1.Value = 0
End If
End If
End Sub
Private Sub CheckCommand()
If message.Contains("LORA_RSSI=") Then
RSSIString = message.Split("="c)(1)
Integer.TryParse(RSSIString, RSSINum)
Dim tempvalue As Integer = 0
tempvalue = RSSINum + 100
If tempvalue * 2 > 100 Then
RSSIPercentage = 100
ElseIf tempvalue * 2 < 0 Then
RSSIPercentage = 0
Else
RSSIPercentage = tempvalue * 2
End If
LoRaConnected = True
ElseIf message.Contains("RED_OK") Then
Debug.Print("Red send ok")
Dim Writer As New StreamWriter(tcpClient.GetStream())
Writer.Write("SET_GREEN=" & HScrollBar2.Value)
Writer.Flush()
ElseIf message.Contains("GREEN_OK") Then
Debug.Print("Green send ok")
Dim Writer As New StreamWriter(tcpClient.GetStream())
Writer.Write("SET_BLUE=" & HScrollBar3.Value)
Writer.Flush()
ElseIf message.Contains("BLUE_OK") Then
Debug.Print("Blue send ok")
Dim Writer As New StreamWriter(tcpClient.GetStream())
Writer.Write("SET_BRIGHT=" & HScrollBar4.Value)
Writer.Flush()
ElseIf message.Contains("BRIGHT_OK") Then
Debug.Print("LED is now on")
Button3.Enabled = True
picTransfering.Visible = False
tmrCheckConnection.Enabled = True
End If
message = ""
Listening()
End Sub
Private Sub Listening()
On Error GoTo errhandler
'Dim Reader As New StreamReader(tcpClient.GetStream())
'While Reader.Peek > -1
'messagebuilder = messagebuilder + Convert.ToChar(Reader.Read()).ToString
'Debug.Print(messagebuilder)
'End While
For i = 0 To 25
CharRead = Convert.ToChar(tcpClient.GetStream.ReadByte).ToString
If CharRead = Chr(10) Or CharRead = Chr(12) Then
Exit For
Else
message = message & CharRead
End If
Next
Debug.Print(message)
CheckCommand()
Exit Sub
errhandler:
Debug.Print("Unable to read from datastream, error #" & Err.Number)
Listening()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
picTransfering.Visible = True
tmrCheckConnection.Enabled = False
Dim Writer As New StreamWriter(tcpClient.GetStream())
Writer.Write("SET_RED=" & HScrollBar1.Value)
Writer.Flush()
'Button3.Enabled = False
End Sub
Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles HScrollBar1.Scroll
PictureBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
Label7.Text = HScrollBar1.Value.ToString
End Sub
Private Sub HScrollBar2_Scroll(sender As Object, e As ScrollEventArgs) Handles HScrollBar2.Scroll
PictureBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
Label8.Text = HScrollBar2.Value.ToString
End Sub
Private Sub HScrollBar3_Scroll(sender As Object, e As ScrollEventArgs) Handles HScrollBar3.Scroll
PictureBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
Label9.Text = HScrollBar3.Value.ToString
End Sub
Private Sub HScrollBar4_Scroll(sender As Object, e As ScrollEventArgs) Handles HScrollBar4.Scroll
PictureBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
Label12.Text = HScrollBar4.Value.ToString
End Sub
Private Sub HScrollBar1_ValueChanged(sender As Object, e As EventArgs) Handles HScrollBar1.ValueChanged
PictureBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
Label7.Text = HScrollBar1.Value.ToString
End Sub
Private Sub HScrollBar2_ValueChanged(sender As Object, e As EventArgs) Handles HScrollBar2.ValueChanged
PictureBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
Label8.Text = HScrollBar2.Value.ToString
End Sub
Private Sub HScrollBar3_ValueChanged(sender As Object, e As EventArgs) Handles HScrollBar3.ValueChanged
PictureBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
Label9.Text = HScrollBar3.Value.ToString
End Sub
Private Sub HScrollBar4_ValueChanged(sender As Object, e As EventArgs) Handles HScrollBar4.ValueChanged
PictureBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
Label12.Text = HScrollBar4.Value.ToString
End Sub
End Class
I've added a picture of how the form exactly looks like (might help with identifying what the code exactly does, if you have any questions about it. please ask them!)