Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for wireless communication using ESP01 #2561

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

AsCress
Copy link
Contributor

@AsCress AsCress commented Nov 2, 2024

THIS IS CURRENTLY A WORK IN PROGRESS.
Fixes #2509
Adds support for wireless communication with the PSLab board using the ESP8266 ESP01 chip.

Screenshots / Recordings

N/A

Checklist:

  • No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

Summary by Sourcery

Add support for wireless communication with the PSLab board using the ESP8266 ESP01 chip, replacing the existing HTTP-based communication with a new SocketClient implementation for improved performance.

New Features:

  • Introduce support for wireless communication with the PSLab board using the ESP8266 ESP01 chip.

Enhancements:

  • Replace HttpAsyncTask with SocketClient for handling wireless communication, improving efficiency and reliability.

Copy link

sourcery-ai bot commented Nov 2, 2024

Reviewer's Guide by Sourcery

This PR implements wireless communication support for the PSLab board using the ESP8266 ESP01 chip. The implementation replaces the existing HTTP-based communication with a socket-based approach, introducing a new SocketClient class for handling TCP/IP connections. The changes modify the communication layer to support both USB and WiFi connections seamlessly.

Sequence diagram for wireless communication using SocketClient

sequenceDiagram
    participant ESPFragment
    participant SocketClient
    participant ScienceLabCommon
    participant ScienceLab
    ESPFragment->>SocketClient: openConnection(espIPAddress, 80)
    SocketClient-->>ESPFragment: isConnected()
    ESPFragment->>ScienceLabCommon: setIsWifiConnected(true)
    ScienceLabCommon->>ScienceLab: openDevice()
    ScienceLab->>PacketHandler: new PacketHandler()
    PacketHandler->>SocketClient: read(buffer, bytesToRead)
    PacketHandler->>SocketClient: write(data)
Loading

Class diagram for the new SocketClient class

classDiagram
    class SocketClient {
        -SocketClient socketClient
        -Socket socket
        -OutputStream outputStream
        -InputStream inputStream
        -boolean isConnected
        -byte[] buffer
        +void openConnection(String ip, int port)
        +static SocketClient getInstance()
        +boolean isConnected()
        +void write(byte[] data)
        +int read(byte[] dest, int bytesToRead)
        +void closeConnection()
    }
    note for SocketClient "Handles TCP/IP connections for wireless communication"
Loading

Updated class diagram for PacketHandler

classDiagram
    class PacketHandler {
        -int timeout
        -int VERSION_STRING_LENGTH
        -int FW_VERSION_LENGTH
        -ByteBuffer burstBuffer
        -SocketClient socketClient
        +PacketHandler(int timeout, CommunicationHandler communicationHandler)
        +PacketHandler()
        +boolean isConnected()
        +int commonRead(int bytesToRead)
        +void commonWrite(byte[] data)
    }
    note for PacketHandler "Replaced HttpAsyncTask with SocketClient for wireless communication"
Loading

File-Level Changes

Change Details Files
Introduced a new socket-based communication implementation
  • Created a singleton SocketClient class for managing TCP/IP connections
  • Implemented methods for opening/closing connections
  • Added read/write operations over socket connection
  • Added connection state management
app/src/main/java/io/pslab/communication/SocketClient.java
Modified packet handling to support both USB and WiFi connections
  • Replaced HTTP async tasks with socket client calls
  • Added WiFi-specific constructor
  • Updated connection status checks to include WiFi state
  • Modified read/write operations to handle both connection types
app/src/main/java/io/pslab/communication/PacketHandler.java
Updated ESP connection handling in the UI
  • Modified ESP connection task to use socket connection
  • Updated connection status feedback
  • Changed return type from String to Boolean for connection status
app/src/main/java/io/pslab/fragment/ESPFragment.java
Enhanced ScienceLab class to support WiFi functionality
  • Added WiFi-specific constructor
  • Updated device connection checks
  • Modified device initialization sequence for WiFi connections
app/src/main/java/io/pslab/communication/ScienceLab.java
app/src/main/java/io/pslab/others/ScienceLabCommon.java

Assessment against linked issues

Issue Objective Addressed Explanation
#2509 Implement wireless (WiFi) connection support using ESP-01 module in the Android app

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@AsCress
Copy link
Contributor Author

AsCress commented Nov 2, 2024

@CloudyPadmal Could you please provide feedback on the fact that if the lines on which I'm working here are correct.
Many things in this PR are currently done ONLY for testing.
It'd be great if you could have a look and provide your feedback if this resembles something which we want to achieve. 🤣
I've not yet configured this properly with the hardware so that I may be able to test this. I'll do that very soon.
Currently, the app only successfully connects to the ESP chip on the board.

@AsCress AsCress self-assigned this Nov 2, 2024
@AsCress AsCress added the In Progress Developer is working on the problem label Nov 2, 2024
Copy link

github-actions bot commented Nov 2, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Progress Developer is working on the problem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support for Wifi (ESP-01) Module in the Android App
1 participant