Giter Site home page Giter Site logo

rpi4_clientside's Introduction

rpi4_clientside

default code of rpi4 client side server.js

const express = require("express");
const app = express();
const PORT = 3000;
// const request = require("request");
const axios = require('axios')
const https = require('https')
const publicIp = "111.22.33.44" //put your Public IP
const localIp = "172.30.1.1" // or put your Private IP 
const serverSidePort = "5500" // Port number portfowarded
let api_url = `http://${publicIp}:${serverSidePort}/gps`;
app.use(express.json())

app.listen(PORT,() => {
	console.log(`it's alive on http://localhost:${PORT}`);
})

let lat = "hi";
let long = "long";
let gpsdms = "GPS";

let gpsData = {
	lat: lat,
	long: long,
	gpsdms: gpsdms
}

app.get("/", (req, res) => {
	return res.send("hello world");
})

function posting() {
	axios
  .post(api_url, gpsData)
  .then(res => {
    console.log(`statusCode: ${res.status}`)
	  console.log(res)
	  console.log(lat);
  })
  .catch(error => {
    console.error(error)
  })
}

setInterval(posting, 1000);

ES6 Version. package.json

import express from "express";
const app = express();
import { SerialPort } from "serialport";
import { ReadlineParser } from "@serialport/parser-readline";


const PORTnum = 3000;
const publicIp = "222.99.193.84";
const localIp = "172.30.1.45";
const serverSidePort = "5500";
let api_url = `http://${publicIp}:${serverSidePort}/gps`;

app.listen(PORTnum, () => {
  console.log(`it's alive on http://localhost:${PORTnum}`);
});

// app.get("/", (req, res) => {
//   res.send("Hello World!");
// });

// app.get("/", (req, res) => {
//   res.sendFile(__dirname + "/index.html");
// });

app.use(express.json());

const port = new SerialPort({
  path: "/dev/cu.usbmodem144301",
  baudRate: 9600,
  dataBits: 8,
  parity: "none",
  stopBits: 1,
  flowControl: false,
});

const parser = port.pipe(new ReadlineParser({ delimiter: "\n" })); //\r\n
parser.on("data", function (data) {
    console.log("data: " + data);
});

console.log(SerialPort);

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.