Skip to content

This is a TCP Socket Server template for the RPI Pico W with features like AES 256 CTR encryption, JSON, Ping System

License

Notifications You must be signed in to change notification settings

HarrisonBT/pico-w-template

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Examples

This template includes example code for the following services

WARNING, be careful on how you do your wiring or you might damage something

  • Adjustable Desk with a 4 pin connector
  • Thermostat for a central heating unit

General

The current features of this template. For the defaults of the features check the Config section

  • Auto close connection if client didn't sent any request in a specific amount of time
  • Set a specific number of simultaneous clients.
  • Max packet size in bytes.
  • Set TCP port.
  • Set the Wifi SSID and Password at compile time
  • JSON format for packet's data
  • AES 256 CTR encryption
  • PING system
  • RTC
  • Method to send a message to all connected clients
  • Method to save data to the flash of the board 256kb
  • Flash UID read at boot and stored in variable FLASH_SERIAL_NUMBER as HEX

The server.cpp could stay untouched, for parsing the data you can just check handler.cpp, after the request is processed the data is sent to the handler along with the client from which you can respond back.

You can keep the connection alive in order to have real time responses

Packets

The packet format is number_of_characters;data e.g. 4;demo

Config file

  • Path: src/config.h

  • Code:

    #ifndef __CONFIG_H__
    #define __CONFIG_H__
    
    #include "pico/cyw43_arch.h"
    
    #define COUNTRY_CODE_0                  'U'
    #define COUNTRY_CODE_1                  'S'
    
    #define WIFI_AUTH                       CYW43_AUTH_WPA2_AES_PSK
    #define WIFI_PASSWORD                   "PASSWORD"
    #define FIRMWARE_VERSION                "0.1.0" // Your version
    #define WIFI_SSID                       "SSID"
    
    /**
    * 1 - Thermostat
    * 2 - Desk
    */
    #define SERVICE_TYPE                    2
    
    // TCP SERVER
    
    #define TCP_SERVER_PORT                 8098
    #define TCP_SERVER_BUF_SIZE             2048
    #define TCP_SERVER_POLL_TIME_S          5
    #define TCP_SERVER_MAX_CLIENTS          5
    #define TCP_SERVER_INACTIVE_TIME_S      35
    
    // ENCRYPTION
    // To disable encryption do not define this variable
    #define AES_ENCRYPTION_KEY              "32-BYTES-KEY-IN-BASE64"
    
    #endif

About

This is a TCP Socket Server template for the RPI Pico W with features like AES 256 CTR encryption, JSON, Ping System

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 85.2%
  • C 14.6%
  • CMake 0.2%