Giter Site home page Giter Site logo

Comments (3)

Tino3141 avatar Tino3141 commented on June 19, 2024

Socket on Device

How to setup

final server = await ServerSocket.bind("192.168.43.1", 4567); // Provided address is the default address 
                                                              // of a device that is hosting a mobile hotspot
server.listen((client) {
   handleConnection(client);
});

Handle Connection

void handleConnection(Socket client) {
    if (kDebugMode) {
      print('Connection from'
      ' ${client.remoteAddress.address}:${client.remotePort}');
    }

    // listen for events from the client
    client.listen(

    	// handle data from the client
    	(Uint8List data) async {
      
     	 if (kDebugMode) {
     	   print(data);
    	 }
     
     	 final message = String.fromCharCodes(data);
    	},

   	 // handle errors
   	onError: (error) {
    	  if (kDebugMode) {
    	    print(error);
    	  }
    	  client.close();
   	 },

   	 // handle the client closing the connection
   	 onDone: () {
    	  if (kDebugMode) {
    	    print('Client left');
     	 }
     	 client.close();
    	},
  );
}  

from nus-cs3237-iot-buoys.

Tino3141 avatar Tino3141 commented on June 19, 2024

IP-Address Issue

For now the IP address is hardcoded into program. Most Android Phones should have the same IP address (192.168.43.1) when hosting their hotspot. However, the IP address can still be different from to phone.

from nus-cs3237-iot-buoys.

leon-thomm avatar leon-thomm commented on June 19, 2024

Because receiving messages from the Phone on the WeMOS did not work reliably using the standard socket api, @Tino3141 and I discontinued these efforts. The problem of attaching the right timestamp was temporarily solved in the following way:

  1. the WeMOS connects to phone wifi
  2. the WeMOS sends reset message
  3. the phone receives reset and resets an internal wemos-alive value
  4. when the WeMOS sends collected data, it sets the timestamp relative to the time at which the reset was sent
  5. when phone receives data, it mutates the timestamp by offsetting it by wemos-alive

We will keep it this way because it works reliably. For publishing a wakeup call we will use MQTT on the WeMOS.

from nus-cs3237-iot-buoys.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.