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

Sigfox Forest Fire Detector
Intermediate
  • 524
  • 4

Full instructions

How to prevent forest from burning? A small Sigfox signal can prevent natural disasters. We will use an Arduino MKRFOX + a flame detector

Control the Injection of a Liquid
Intermediate
  • 283
  • 2

Protip

Control the injection of a liquid with GOBLIN 2 from anywhere via Ubidots platform.

How to build a text to speech IOT speaker
Intermediate
  • 115
  • 1

Full instructions

In this project we'll be building a speaker that has text to speech ability and will expose a secure API for remote control.

Otto DIY+ Arduino Bluetooth robot easy to 3dprint
Intermediate
  • 12,223
  • 58

Work in progress

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

C.H.I.P.py Ruxpin ʕ•ᴥ•ʔ
Intermediate
  • 48,567
  • 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!

Spideruino
Intermediate
  • 12,334
  • 54

A Lego arachnid controlled by your smartphone.

Add projectSign up / Login