Things used in this project

Hardware components:
Screen%20shot%202016 07 25%20at%2012.46.01%20pm
C.H.I.P. Pocket C.H.I.P.
×2
Chip%20v1
C.H.I.P.
×1
12994 02
Raspberry Pi Raspberry Pi 1 Model B+
×1

Code

server.goGo
sample of server code
package main

import (
	"bytes"
	"fmt"
	"gitlab.com/bobburns/famsess"
	"log"
	"net"
	"os"
)

func main() {
	service := ":16538"
	tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	for {
		conn, err := listener.Accept()
		if err != nil {
			continue
		}
		defer conn.Close()
		fmt.Println("listening on port ", service)
		go handleClient(conn)
	}
}
func handleClient(conn net.Conn) {
	s := session.NewSession(conn)

	for {
		log.Println("main loop")
		err := s.ParseIncoming()
		if err != nil {
			log.Printf("Error ParseIncoming [%s]\n", err)
			break
		}

		switch {
		  
		case bytes.Equal(s.RecOp[0:4], session.SendMPre[0:4]):
			log.Println("got SENDMPRE")
			err = s.MessagePreRecv()
		case bytes.Equal(s.RecOp[0:4], session.SendMess[0:4]):
			err = s.MessageRecv()
		case bytes.Equal(s.RecOp[0:4], session.RetrMess[0:4]):
			err = s.MessageRetr()
		case bytes.Equal(s.RecOp[0:4], session.ClientAuth[0:4]):
			err = s.ServerAuth()
		case bytes.Equal(s.RecOp[0:4], session.MessInit[0:4]):
			err = s.MessageInit()
		case bytes.Equal(s.RecOp[0:4], session.ReqMeta[0:4]):
			err = s.ServMeta()
		case bytes.Equal(s.RecOp[0:4], session.DelMess[0:4]):
			err = s.MessageServDel()
		case bytes.Equal(s.RecOp[0:4], session.CChPass[0:4]):
			err = s.ServerChgPass()

		}
		if err != nil {
			// how to handle errors?
			log.Println(err)
		}
		fmt.Println(s.RecOp[0:4])
	}
}

func checkError(err error) {
	if err != nil {
		fmt.Printf("Error: %s\n", err)
		os.Exit(1)
	}
}

Credits

8biticon jec6fced6s
Bob Burns

Started programming again after 25? years. Currently super into Golang and what it can do with pocketCHIP.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Third Eye for The Blind
Intermediate
  • 518
  • 8

Full instructions

An innovative wearable technology for visually impaired peoples.

Roomba Dashboard - A CLI Dashboard for iRobot Create 2
Intermediate
  • 165
  • 1

Roomba-Dash is a CLI dashboard for the iRobot Create 2 platform written in Golang. It is cross-platform compatible.

Push for Pizza Using Proximus Public LoRaWAN Connectivity
Intermediate
  • 145
  • 0

A simple push button using Proximus public LPWAN connectivity. Optimized for power consumption (<30 microAmps) and long distance (>15km!).

C.H.I.P.py Ruxpin ʕ•ᴥ•ʔ
Intermediate
  • 47,264
  • 73

Full instructions

Bring Teddy Ruxpin back to life, but on your own terms! Make him say whatever you want, or have him search twitter to read tweets!

Otto DIY +
Intermediate
  • 7,721
  • 50

Work in progress

"Otto DIY with steroids" + Bluetooth + APP + switch + sensors + strength +...

Otto DIY +

Team Otto builders

El Wire T-shirt: Connected to a LightBlue Bean
Intermediate
  • 177
  • 6

Work in progress

A custom Internet connected shirt using a LightBlue Bean to light up the shirt's El Wire graphics.

Add projectSign up / Login