5 |
6 |
7 | #include "MQTTClient.h"
8 | #include "sdkconfig.h"
9 |
10 | static char tag[] = "mqtt_paho";
11 | static unsigned char sendBuf[1000];
12 | static unsigned char readBuf[1000];
13 | Network network;
14 | static void messageHandler_func(MessageData *md) {
15 | ESP_LOGD(tag, "Subscription received!: %.*s", md->topicName->lenstring.len, md->topicName->lenstring.data);
16 | }
17 |
18 | void task_paho(void *ignore) {
19 | ESP_LOGD(tag, "Starting ...");
20 | int rc;
21 | MQTTClient client;
22 | NetworkInit(&network);
23 | ESP_LOGD(tag, "NetworkConnect ...");
24 | NetworkConnect(&network, "192.168.1.105", 1883);
25 | ESP_LOGD(tag, "MQTTClientInit ...");
26 | MQTTClientInit(&client, &network,
27 | 1000, // command_timeout_ms
28 | sendBuf, //sendbuf,
29 | sizeof(sendBuf), //sendbuf_size,
30 | readBuf, //readbuf,
31 | sizeof(readBuf) //readbuf_size
32 | );
33 |
34 | MQTTString clientId = MQTTString_initializer;
35 | clientId.cstring = "MYCLIENT1";
36 |
37 | MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
38 | data.clientID = clientId;
39 | data.willFlag = 0;
40 | data.MQTTVersion = 3;
41 | data.keepAliveInterval = 0;
42 | data.cleansession = 1;
43 |
44 | ESP_LOGD(tag, "MQTTConnect ...");
45 | rc = MQTTConnect(&client, &data);
46 | if (rc != SUCCESS) {
47 | ESP_LOGE(tag, "MQTTConnect: %d", rc);
48 | }
49 |
50 | ESP_LOGD(tag, "MQTTSubscribe ...");
51 | rc = MQTTSubscribe(&client, "test1", QOS0, messageHandler_func);
52 | if (rc != SUCCESS) {
53 | ESP_LOGE(tag, "MQTTSubscribe: %d", rc);
54 | }
55 | while(1) {
56 | MQTTYield(&client, 1000);
57 | }
58 | vTaskDelete(NULL);
59 | }
60 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTClient-C/samples/linux/build.sh:
--------------------------------------------------------------------------------
1 | cp ../../src/MQTTClient.c .
2 | sed -e 's/""/"MQTTLinux.h"/g' ../../src/MQTTClient.h > MQTTClient.h
3 | gcc stdoutsub.c -I ../../src -I ../../src/linux -I ../../../MQTTPacket/src MQTTClient.c ../../src/linux/MQTTLinux.c ../../../MQTTPacket/src/MQTTFormat.c ../../../MQTTPacket/src/MQTTPacket.c ../../../MQTTPacket/src/MQTTDeserializePublish.c ../../../MQTTPacket/src/MQTTConnectClient.c ../../../MQTTPacket/src/MQTTSubscribeClient.c ../../../MQTTPacket/src/MQTTSerializePublish.c -o stdoutsub ../../../MQTTPacket/src/MQTTConnectServer.c ../../../MQTTPacket/src/MQTTSubscribeServer.c ../../../MQTTPacket/src/MQTTUnsubscribeServer.c ../../../MQTTPacket/src/MQTTUnsubscribeClient.c
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTClient-C/src/cc3200/MQTTCC3200.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Allan Stockdill-Mander - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #ifndef __MQTT_CC3200_
18 | #define __MQTT_CC3200_
19 |
20 | #include "simplelink.h"
21 | #include "netapp.h"
22 | #include "socket.h"
23 | #include "hw_types.h"
24 | #include "systick.h"
25 |
26 | typedef struct Timer Timer;
27 |
28 | struct Timer {
29 | unsigned long systick_period;
30 | unsigned long end_time;
31 | };
32 |
33 | typedef struct Network Network;
34 |
35 | struct Network
36 | {
37 | int my_socket;
38 | int (*mqttread) (Network*, unsigned char*, int, int);
39 | int (*mqttwrite) (Network*, unsigned char*, int, int);
40 | void (*disconnect) (Network*);
41 | };
42 |
43 | char expired(Timer*);
44 | void countdown_ms(Timer*, unsigned int);
45 | void countdown(Timer*, unsigned int);
46 | int left_ms(Timer*);
47 |
48 | void InitTimer(Timer*);
49 |
50 | int cc3200_read(Network*, unsigned char*, int, int);
51 | int cc3200_write(Network*, unsigned char*, int, int);
52 | void cc3200_disconnect(Network*);
53 | void NewNetwork(Network*);
54 |
55 | int ConnectNetwork(Network*, char*, int);
56 | int TLSConnectNetwork(Network*, char*, int, SlSockSecureFiles_t*, unsigned char, unsigned int, char);
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/build.sh:
--------------------------------------------------------------------------------
1 | g++ hello.cpp -I ../../src/ -I ../../src/linux -I ../../../MQTTPacket/src ../../../MQTTPacket/src/MQTTPacket.c ../../../MQTTPacket/src/MQTTDeserializePublish.c ../../../MQTTPacket/src/MQTTConnectClient.c ../../../MQTTPacket/src/MQTTSubscribeClient.c ../../../MQTTPacket/src/MQTTSerializePublish.c ../../../MQTTPacket/src/MQTTUnsubscribeClient.c -o hello
2 |
3 | g++ -g stdoutsub.cpp -I ../../src -I ../../src/linux -I ../../../MQTTPacket/src ../../../MQTTPacket/src/MQTTFormat.c ../../../MQTTPacket/src/MQTTPacket.c ../../../MQTTPacket/src/MQTTDeserializePublish.c ../../../MQTTPacket/src/MQTTConnectClient.c ../../../MQTTPacket/src/MQTTSubscribeClient.c ../../../MQTTPacket/src/MQTTSerializePublish.c -o stdoutsub ../../../MQTTPacket/src/MQTTConnectServer.c ../../../MQTTPacket/src/MQTTSubscribeServer.c ../../../MQTTPacket/src/MQTTUnsubscribeServer.c ../../../MQTTPacket/src/MQTTUnsubscribeClient.c
4 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/hello:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/hello
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/stdoutsub:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/stdoutsub
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/src/MQTTLogging.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #if !defined(MQTT_LOGGING_H)
18 | #define MQTT_LOGGING_H
19 |
20 | #define STREAM stdout
21 | #if !defined(DEBUG)
22 | #define DEBUG(...) \
23 | {\
24 | fprintf(STREAM, "DEBUG: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \
25 | fprintf(STREAM, ##__VA_ARGS__); \
26 | fflush(STREAM); \
27 | }
28 | #endif
29 | #if !defined(LOG)
30 | #define LOG(...) \
31 | {\
32 | fprintf(STREAM, "LOG: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \
33 | fprintf(STREAM, ##__VA_ARGS__); \
34 | fflush(STREAM); \
35 | }
36 | #endif
37 | #if !defined(WARN)
38 | #define WARN(...) \
39 | { \
40 | fprintf(STREAM, "WARN: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \
41 | fprintf(STREAM, ##__VA_ARGS__); \
42 | fflush(STREAM); \
43 | }
44 | #endif
45 | #if !defined(ERROR)
46 | #define ERROR(...) \
47 | { \
48 | fprintf(STREAM, "ERROR: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \
49 | fprintf(STREAM, ##__VA_ARGS__); \
50 | fflush(STREAM); \
51 | exit(1); \
52 | }
53 | #endif
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/src/arduino/Countdown.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #if !defined(COUNTDOWN_H)
18 | #define COUNTDOWN_H
19 |
20 | class Countdown
21 | {
22 | public:
23 | Countdown()
24 | {
25 | interval_end_ms = 0L;
26 | }
27 |
28 | Countdown(int ms)
29 | {
30 | countdown_ms(ms);
31 | }
32 |
33 | bool expired()
34 | {
35 | return (interval_end_ms > 0L) && (millis() >= interval_end_ms);
36 | }
37 |
38 | void countdown_ms(unsigned long ms)
39 | {
40 | interval_end_ms = millis() + ms;
41 | }
42 |
43 | void countdown(int seconds)
44 | {
45 | countdown_ms((unsigned long)seconds * 1000L);
46 | }
47 |
48 | int left_ms()
49 | {
50 | return interval_end_ms - millis();
51 | }
52 |
53 | private:
54 | unsigned long interval_end_ms;
55 | };
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/src/mbed/MQTTEthernet.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #if !defined(MQTTETHERNET_H)
18 | #define MQTTETHERNET_H
19 |
20 | #include "MQTT_mbed.h"
21 | #include "EthernetInterface.h"
22 | #include "MQTTSocket.h"
23 |
24 | class MQTTEthernet : public MQTTSocket
25 | {
26 | public:
27 | MQTTEthernet()
28 | {
29 | eth.init(); // Use DHCP
30 | eth.connect();
31 | }
32 |
33 | private:
34 |
35 | EthernetInterface eth;
36 |
37 | };
38 |
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/src/mbed/MQTTSocket.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #if !defined(MQTTSOCKET_H)
18 | #define MQTTSOCKET_H
19 |
20 | #include "MQTT_mbed.h"
21 | #include "TCPSocketConnection.h"
22 |
23 | class MQTTSocket
24 | {
25 | public:
26 | int connect(char* hostname, int port, int timeout=1000)
27 | {
28 | mysock.set_blocking(false, timeout); // 1 second Timeout
29 | return mysock.connect(hostname, port);
30 | }
31 |
32 | int read(unsigned char* buffer, int len, int timeout)
33 | {
34 | mysock.set_blocking(false, timeout);
35 | return mysock.receive((char*)buffer, len);
36 | }
37 |
38 | int write(unsigned char* buffer, int len, int timeout)
39 | {
40 | mysock.set_blocking(false, timeout);
41 | return mysock.send((char*)buffer, len);
42 | }
43 |
44 | int disconnect()
45 | {
46 | return mysock.close();
47 | }
48 |
49 | private:
50 |
51 | TCPSocketConnection mysock;
52 |
53 | };
54 |
55 |
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/samples/build:
--------------------------------------------------------------------------------
1 | gcc -Wall -c transport.c -Os -s
2 | gcc qos0pub.c transport.o -I ../src ../src/MQTTConnectClient.c ../src/MQTTSerializePublish.c ../src/MQTTPacket.c -o qos0pub -Os -s
3 |
4 | gcc pub0sub1.c transport.o -I ../src ../src/MQTTConnectClient.c ../src/MQTTSerializePublish.c ../src/MQTTPacket.c ../src/MQTTSubscribeClient.c -o pub0sub1 ../src/MQTTDeserializePublish.c -Os -s ../src/MQTTConnectServer.c ../src/MQTTSubscribeServer.c ../src/MQTTUnsubscribeServer.c ../src/MQTTUnsubscribeClient.c -ggdb
5 | gcc pub0sub1_nb.c transport.o -I ../src ../src/MQTTConnectClient.c ../src/MQTTSerializePublish.c ../src/MQTTPacket.c ../src/MQTTSubscribeClient.c -o pub0sub1_nb ../src/MQTTDeserializePublish.c -Os -s ../src/MQTTConnectServer.c ../src/MQTTSubscribeServer.c ../src/MQTTUnsubscribeServer.c ../src/MQTTUnsubscribeClient.c -ggdb
6 |
7 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/samples/null.c:
--------------------------------------------------------------------------------
1 | int main(int argc, char** argv)
2 | {
3 | return 0;
4 | }
5 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/samples/transport.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Sergio R. Caprile - "commonalization" from prior samples and/or documentation extension
16 | *******************************************************************************/
17 |
18 | int transport_sendPacketBuffer(int sock, unsigned char* buf, int buflen);
19 | int transport_getdata(unsigned char* buf, int count);
20 | int transport_getdatanb(void *sck, unsigned char* buf, int count);
21 | int transport_open(char* host, int port);
22 | int transport_close(int sock);
23 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/src/MQTTPublish.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Xiang Rong - 442039 Add makefile to Embedded C client
16 | *******************************************************************************/
17 |
18 | #ifndef MQTTPUBLISH_H_
19 | #define MQTTPUBLISH_H_
20 |
21 | #if !defined(DLLImport)
22 | #define DLLImport
23 | #endif
24 | #if !defined(DLLExport)
25 | #define DLLExport
26 | #endif
27 |
28 | DLLExport int MQTTSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid,
29 | MQTTString topicName, unsigned char* payload, int payloadlen);
30 |
31 | DLLExport int MQTTDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTString* topicName,
32 | unsigned char** payload, int* payloadlen, unsigned char* buf, int len);
33 |
34 | DLLExport int MQTTSerialize_puback(unsigned char* buf, int buflen, unsigned short packetid);
35 | DLLExport int MQTTSerialize_pubrel(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid);
36 | DLLExport int MQTTSerialize_pubcomp(unsigned char* buf, int buflen, unsigned short packetid);
37 |
38 | #endif /* MQTTPUBLISH_H_ */
39 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/src/MQTTSubscribe.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Xiang Rong - 442039 Add makefile to Embedded C client
16 | *******************************************************************************/
17 |
18 | #ifndef MQTTSUBSCRIBE_H_
19 | #define MQTTSUBSCRIBE_H_
20 |
21 | #if !defined(DLLImport)
22 | #define DLLImport
23 | #endif
24 | #if !defined(DLLExport)
25 | #define DLLExport
26 | #endif
27 |
28 | DLLExport int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid,
29 | int count, MQTTString topicFilters[], int requestedQoSs[]);
30 |
31 | DLLExport int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid,
32 | int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], unsigned char* buf, int len);
33 |
34 | DLLExport int MQTTSerialize_suback(unsigned char* buf, int buflen, unsigned short packetid, int count, int* grantedQoSs);
35 |
36 | DLLExport int MQTTDeserialize_suback(unsigned short* packetid, int maxcount, int* count, int grantedQoSs[], unsigned char* buf, int len);
37 |
38 |
39 | #endif /* MQTTSUBSCRIBE_H_ */
40 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/src/MQTTUnsubscribe.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Xiang Rong - 442039 Add makefile to Embedded C client
16 | *******************************************************************************/
17 |
18 | #ifndef MQTTUNSUBSCRIBE_H_
19 | #define MQTTUNSUBSCRIBE_H_
20 |
21 | #if !defined(DLLImport)
22 | #define DLLImport
23 | #endif
24 | #if !defined(DLLExport)
25 | #define DLLExport
26 | #endif
27 |
28 | DLLExport int MQTTSerialize_unsubscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid,
29 | int count, MQTTString topicFilters[]);
30 |
31 | DLLExport int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int max_count, int* count, MQTTString topicFilters[],
32 | unsigned char* buf, int len);
33 |
34 | DLLExport int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid);
35 |
36 | DLLExport int MQTTDeserialize_unsuback(unsigned short* packetid, unsigned char* buf, int len);
37 |
38 | #endif /* MQTTUNSUBSCRIBE_H_ */
39 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/test/build_test:
--------------------------------------------------------------------------------
1 | gcc -Wall test1.c -o test1 -I../src ../src/MQTTConnectClient.c ../src/MQTTConnectServer.c ../src/MQTTPacket.c ../src/MQTTSerializePublish.c ../src/MQTTDeserializePublish.c ../src/MQTTSubscribeServer.c ../src/MQTTSubscribeClient.c ../src/MQTTUnsubscribeServer.c ../src/MQTTUnsubscribeClient.c
2 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/about.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | About
5 |
6 |
7 | About This Content
8 |
9 | December 9, 2013
10 | License
11 |
12 | The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
13 | indicated below, the Content is provided to you under the terms and conditions of the
14 | Eclipse Public License Version 1.0 ("EPL") and Eclipse Distribution License Version 1.0 ("EDL").
15 | A copy of the EPL is available at
16 | http://www.eclipse.org/legal/epl-v10.html
17 | and a copy of the EDL is available at
18 | http://www.eclipse.org/org/documents/edl-v10.php.
19 | For purposes of the EPL, "Program" will mean the Content.
20 |
21 | If you did not receive this Content directly from the Eclipse Foundation, the Content is
22 | being redistributed by another party ("Redistributor") and different terms and conditions may
23 | apply to your use of any object code in the Content. Check the Redistributor's license that was
24 | provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
25 | indicated below, the terms and conditions of the EPL still apply to any source code in the Content
26 | and such source code may be obtained at http://www.eclipse.org.
27 |
28 |
29 |
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/component.mk:
--------------------------------------------------------------------------------
1 | COMPONENT_SRCDIRS=MQTTClient-C/src MQTTPacket/src MQTTClient-C/src/linux
2 | COMPONENT_ADD_INCLUDEDIRS=MQTTClient-C/src MQTTPacket/src MQTTClient-C/src/linux
--------------------------------------------------------------------------------
/networking/mqtt/paho_mqtt_embedded_c/edl-v10:
--------------------------------------------------------------------------------
1 |
2 | Eclipse Distribution License - v 1.0
3 |
4 | Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
5 |
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9 |
10 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12 | Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 |
16 |
--------------------------------------------------------------------------------
/networking/telnet/.gitignore:
--------------------------------------------------------------------------------
1 | build/
2 | sdkconfig.old
3 | components/
4 |
--------------------------------------------------------------------------------
/networking/telnet/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a
3 | # project subdirectory.
4 | #
5 |
6 | PROJECT_NAME := app-template
7 |
8 | include $(IDF_PATH)/make/project.mk
9 |
10 |
--------------------------------------------------------------------------------
/networking/telnet/README.md:
--------------------------------------------------------------------------------
1 | #Telnet
2 | This sample illustrates the use of the libtelnet library that can be
3 | read about here:
4 |
5 | [https://github.com/seanmiddleditch/libtelnet](https://github.com/seanmiddleditch/libtelnet)
6 |
7 | The sample connects to a WiFi access point and then starts to listen on
8 | TCP port 23 (Telnet) for an incoming client request.
9 |
10 | ##Addition of libtelnet
11 | To install the libtelnet component:
12 |
13 | 1. Create a sub-directory called `components`.
14 | 2. Change into `components`.
15 | 3. Clone the libtelnet repository:
16 | ```
17 | $ git clone https://github.com/seanmiddleditch/libtelnet.git
18 | ```
19 | 4. Change into `libtelnet`
20 | 5. Create a directory called `include`.
21 | 6. Copy all the `*.h` files into `include`:
22 | ```
23 | $ cp *.h include/
24 | ```
25 | 7. Create a `component.mk` file that contains:
26 | ```
27 | include $(IDF_PATH)/make/component_common.mk
28 | ```
--------------------------------------------------------------------------------
/networking/telnet/main/component.mk:
--------------------------------------------------------------------------------
1 | #
2 | # Main Makefile. This is basically the same as a component makefile.
3 | #
4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default,
5 | # this will take the sources in the src/ directory, compile them and link them into
6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
7 | # please read the ESP-IDF documents if you need to do this.
8 | #
9 | COMPONENT_ADD_INCLUDEDIRS=.
10 | include $(IDF_PATH)/make/component_common.mk
11 |
--------------------------------------------------------------------------------
/networking/telnet/main/telnet.h:
--------------------------------------------------------------------------------
1 | void telnet_esp32_listenForClients(void (*callbackParam)(uint8_t *buffer, size_t size));
2 | void telnet_esp32_sendData(uint8_t *buffer, size_t size);
3 | int telnet_esp32_vprintf(const char *fmt, va_list va);
4 |
--------------------------------------------------------------------------------
/nvs/fragments/errorToString.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/nvs/fragments/errorToString.c
--------------------------------------------------------------------------------
/partitions/fragments/partitionSubtypeToString.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | const char *partitionSubtypeToString(esp_partition_subtype_t subtype) {
4 | switch(subtype) {
5 | case ESP_PARTITION_SUBTYPE_APP_FACTORY:
6 | return "APP_FACTORY";
7 | case ESP_PARTITION_SUBTYPE_APP_OTA_0:
8 | return "APP_OTA_0";
9 | case ESP_PARTITION_SUBTYPE_APP_OTA_1:
10 | return "APP_OTA_1";
11 | case ESP_PARTITION_SUBTYPE_APP_OTA_10:
12 | return "APP_OTA_10";
13 | case ESP_PARTITION_SUBTYPE_APP_OTA_11:
14 | return "APP_OTA_11";
15 | case ESP_PARTITION_SUBTYPE_APP_OTA_12:
16 | return "APP_OTA_12";
17 | case ESP_PARTITION_SUBTYPE_APP_OTA_13:
18 | return "APP_OTA_13";
19 | case ESP_PARTITION_SUBTYPE_APP_OTA_14:
20 | return "APP_OTA_14";
21 | case ESP_PARTITION_SUBTYPE_APP_OTA_15:
22 | return "APP_OTA_15";
23 | case ESP_PARTITION_SUBTYPE_APP_OTA_2:
24 | return "APP_OTA_2";
25 | case ESP_PARTITION_SUBTYPE_APP_OTA_3:
26 | return "APP_OTA_3";
27 | case ESP_PARTITION_SUBTYPE_APP_OTA_4:
28 | return "APP_OTA_4";
29 | case ESP_PARTITION_SUBTYPE_APP_OTA_5:
30 | return "APP_OTA_5";
31 | case ESP_PARTITION_SUBTYPE_APP_OTA_6:
32 | return "APP_OTA_6";
33 | case ESP_PARTITION_SUBTYPE_APP_OTA_7:
34 | return "APP_OTA_7";
35 | case ESP_PARTITION_SUBTYPE_APP_OTA_8:
36 | return "APP_OTA_8";
37 | case ESP_PARTITION_SUBTYPE_APP_OTA_9:
38 | return "APP_OTA_9";
39 | case ESP_PARTITION_SUBTYPE_APP_TEST:
40 | return "APP_TEST";
41 | case ESP_PARTITION_SUBTYPE_DATA_ESPHTTPD:
42 | return "DATA_ESPHTTPD";
43 | case ESP_PARTITION_SUBTYPE_DATA_FAT:
44 | return "DATA_FAT";
45 | case ESP_PARTITION_SUBTYPE_DATA_NVS:
46 | return "DATA_NVS";
47 | case ESP_PARTITION_SUBTYPE_DATA_OTA:
48 | return "DATA_OTA";
49 | case ESP_PARTITION_SUBTYPE_DATA_PHY:
50 | return "DATA_PHY";
51 | case ESP_PARTITION_SUBTYPE_DATA_SPIFFS:
52 | return "DATA_SPIFFS";
53 | default:
54 | return "Unknown";
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/partitions/fragments/partitionTypeToString.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | const char *partitionTypeToString(esp_partition_type_t type) {
4 | switch(type) {
5 | case ESP_PARTITION_TYPE_APP:
6 | return "APP";
7 | case ESP_PARTITION_TYPE_DATA:
8 | return "DATA";
9 | default:
10 | return "Unknown";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/posix/README.md:
--------------------------------------------------------------------------------
1 | # POSIX
2 | Posix is the specification for Unix like functions. The ESP-IDF provides many implementations for Posix functions but some are omitted and thus should not be used in ESP32 based applications. However there are times when we received 3rd party code that uses a Posix function that we don't have in our environment. Our choices then become:
3 |
4 | * Contact the 3rd party provider and ask them to alter their code to remove it, replace it or make it optional.
5 | * Contact Espressif and ask them to add support for the missing Posix function.
6 | * Provide a shim that satisfies the Posix function using the capabailities that are available to us.
7 |
8 | In the source file called `posix_shims.c` we provide some of those shims.
--------------------------------------------------------------------------------
/posix/posix_shims.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | /**
6 | * @brief Provide a shim for the Posix access(2) function.
7 | * @param [in] pathname The file to check.
8 | * @param [in] mode The mode of access requested.
9 | * @return 0 on success, -1 on error with errno set.
10 | */
11 | int access(const char *pathname, int mode) {
12 | struct stat statBuf;
13 | if (stat(pathname, &statBuf) == -1) {
14 | errno = ENOENT;
15 | return -1;
16 | }
17 | return 0; // Indicate that all we have access to the file.
18 | } // access
19 |
--------------------------------------------------------------------------------
/pwm/README.md:
--------------------------------------------------------------------------------
1 | ### See also
2 | * hardware/servos
--------------------------------------------------------------------------------
/rmt/README.md:
--------------------------------------------------------------------------------
1 | ### See also
2 | * hardware/neopixels
3 | * hardware/infrared
--------------------------------------------------------------------------------
/skeletons/cpp/README.md:
--------------------------------------------------------------------------------
1 | # C++ Skeletons
2 | This directory contains some skeletons for main files for C++ applications.
3 |
4 | * `main_helloworld.cpp` - Simple main startup.
5 | * `main_network.cpp` - Simple main with networking via WiFi.
--------------------------------------------------------------------------------
/skeletons/cpp/main_helloworld.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * 1. Open up the project properties
3 | * 2. Visit C/C++ General > Preprocessor Include Paths, Macros, etc
4 | * 3. Select the Providers tab
5 | * 4. Check the box for "CDT GCC Built-in Compiler Settings"
6 | * 5. Set the compiler spec command to "xtensa-esp32-elf-gcc ${FLAGS} -E -P -v -dD "${INPUTS}""
7 | * 6. Rebuild the index
8 | */
9 |
10 | #include
11 | #include
12 | #include "sdkconfig.h"
13 |
14 |
15 | static char tag[]="cpp_helloworld";
16 |
17 | extern "C" {
18 | void app_main(void);
19 | }
20 |
21 | class Greeting {
22 | public:
23 | void helloEnglish() {
24 | ESP_LOGD(tag, "Hello %s", name.c_str());
25 | }
26 |
27 | void helloFrench() {
28 | ESP_LOGD(tag, "Bonjour %s", name.c_str());
29 | }
30 |
31 | void setName(std::string name) {
32 | this->name = name;
33 | }
34 | private:
35 | std::string name = "";
36 |
37 | };
38 |
39 | void app_main(void)
40 | {
41 | Greeting myGreeting;
42 | myGreeting.setName("Neil");
43 | myGreeting.helloEnglish();
44 | myGreeting.helloFrench();
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/skeletons/cpp/main_network.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include "sdkconfig.h"
7 |
8 | static char tag[] = "my tag";
9 | extern "C" {
10 | void app_main(void);
11 | }
12 |
13 | class MyWiFiEventHandler: public WiFiEventHandler {
14 |
15 | esp_err_t staGotIp(system_event_sta_got_ip_t event_sta_got_ip) {
16 | ESP_LOGD(tag, "MyWiFiEventHandler(Class): staGotIp");
17 | // Do something
18 | return ESP_OK;
19 | }
20 | };
21 |
22 | void app_main(void)
23 | {
24 | WiFi wifi;
25 | MyWiFiEventHandler *eventHandler = new MyWiFiEventHandler();
26 |
27 | wifi.setWifiEventHandler(eventHandler);
28 | wifi.setIPInfo("192.168.1.99", "192.168.1.1", "255.255.255.0");
29 | wifi.connectAP("myssid", "mypassword");
30 | }
31 |
--------------------------------------------------------------------------------
/sntp/fragments/sntp.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "sdkconfig.h"
9 |
10 | /*
11 | * Connect to an Internet time server to get the current date and
12 | * time.
13 | */
14 | void startSNTP() {
15 | ip_addr_t addr;
16 | sntp_setoperatingmode(SNTP_OPMODE_POLL);
17 | inet_pton(AF_INET, "129.6.15.28", &addr);
18 | sntp_setserver(0, &addr);
19 | sntp_init();
20 | }
21 |
--------------------------------------------------------------------------------
/sockets/client/socketClient.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "sdkconfig.h"
8 |
9 | static char tag[] = "socketClient";
10 |
11 | void socketClient(void *ignore) {
12 | ESP_LOGD(tag, "start");
13 | int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
14 |
15 | ESP_LOGD(tag, "socket: rc: %d", sock);
16 | struct sockaddr_in serverAddress;
17 | serverAddress.sin_family = AF_INET;
18 | inet_pton(AF_INET, "192.168.1.200", &serverAddress.sin_addr.s_addr);
19 | serverAddress.sin_port = htons(9999);
20 |
21 | int rc = connect(sock, (struct sockaddr *)&serverAddress, sizeof(struct sockaddr_in));
22 | ESP_LOGD(tag, "connect rc: %d", rc);
23 |
24 | char *data = "Hello world";
25 | rc = send(sock, data, strlen(data), 0);
26 | ESP_LOGD(tag, "send: rc: %d", rc);
27 |
28 | rc = close(sock);
29 | ESP_LOGD(tag, "close: rc: %d", rc);
30 |
31 | vTaskDelete(NULL);
32 | }
33 |
--------------------------------------------------------------------------------
/sockets/utilities/socket_utils.c:
--------------------------------------------------------------------------------
1 | #include "lwip/socket.h"
2 |
3 | static void dumpSockaddr(struct sockaddr_in address) {
4 | ESP_LOGD(tag, "Address details:");
5 | char *family = "Unknown";
6 | unsigned short port;
7 | char ipString[20];
8 |
9 | if (address.sin_family == AF_INET) {
10 | family = "AF_INET";
11 | } else if (address.sin_family == AF_INET6) {
12 | family = "AF_INET6";
13 | }
14 | port = ntohs(address.sin_port);
15 | inet_ntop(address.sin_family, &address.sin_addr, ipString, sizeof(ipString)) ;
16 | ESP_LOGD(tag, "Address details: family=%s, ip=%s, port=%d", family, ipString, port);
17 | }
18 |
--------------------------------------------------------------------------------
/tasks/watchdogs/README.md:
--------------------------------------------------------------------------------
1 | # Watchdogs
2 | This is a sample application that illustrates the capabilities of watchdogs and watchdog processing.
3 |
4 | A related YouTube video is available here:
5 |
6 | https://www.youtube.com/watch?v=C2xF3O6qkbg
--------------------------------------------------------------------------------
/tools/bootloaderExamine/.gitignore:
--------------------------------------------------------------------------------
1 | /a.out
2 | /app-template.bin
3 |
--------------------------------------------------------------------------------
/tools/esptool_libs/README.md:
--------------------------------------------------------------------------------
1 | # Esptool libraries
2 | The Espressif awesome esptool performs just about anything you may want to do relating to ESP32 programming over UART. It can write to flash, write to memory, erase flash and a world of other features. The specification of the protocol can be found in the `esptool` github project Wiki.
3 |
4 | This section of this repository hosts libraries for working with this protocol. There is an implementation in Node.js and more to come including C and C++.
--------------------------------------------------------------------------------
/tools/esptool_libs/nodejs/README.md:
--------------------------------------------------------------------------------
1 | # NodeJS ESP Tools
2 |
3 | The `build.js` tool is used to take the `stub_flasher_32.elf` and break it apart into the separate files that need to be individually pushed to ESP32 RAM for execution.
--------------------------------------------------------------------------------
/tools/esptool_libs/nodejs/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Extract the text and data sections to their own files.
3 | xtensa-esp32-elf-objcopy \
4 | --dump-section .text=text.dat \
5 | --dump-section .data=data.dat \
6 | stub_flasher_32.elf
7 |
8 | # Parse out the text load address, the data load address and the entry point from the ELF.
9 | text_address=`xtensa-esp32-elf-objdump --section-headers --wide --section=.text stub_flasher_32.elf | sed -n '$s/^\s*[[:alnum:]]*\s*\S*\s*[[:alnum:]]*\s*[[:alnum:]]*\s*\([[:alnum:]]*\).*/\1/p'`
10 | #echo "Text address: 0x${text_address}"
11 | data_address=`xtensa-esp32-elf-objdump --section-headers --wide --section=.data stub_flasher_32.elf | sed -n '$s/^\s*[[:alnum:]]*\s*\S*\s*[[:alnum:]]*\s*[[:alnum:]]*\s*\([[:alnum:]]*\).*/\1/p'`
12 | #echo "Data address: 0x${data_address}"
13 | entry_point=`xtensa-esp32-elf-objdump --wide --file-headers stub_flasher_32.elf | sed -n '/start address/s/start address 0x\([[:alnum:]]\)/\1/p'`
14 | #echo "Entry point: 0x${entry_point}"
15 |
16 | echo "{"
17 | echo " \"textAddress\": \"${text_address}\","
18 | echo " \"dataAddress\": \"${data_address}\","
19 | echo " \"entryPoint\": \"${entry_point}\","
20 | echo " \"textData\": \"$(base64 --wrap=0 text.dat)\","
21 | echo " \"dataData\": \"$(base64 --wrap=0 data.dat)\""
22 | echo "}"
23 |
24 | # Remove the temporary text and data files.
25 | #rm text.dat data.dat
26 |
--------------------------------------------------------------------------------
/tools/sdkconfig_compare/README.md:
--------------------------------------------------------------------------------
1 | This is a node.js application which takes as input two files. Each file should be an ESP-IDF `sdkconfig` file. The tool compares the two files and logs the logical distinctions between them. For example, if one file has an entry while the other doesn't, that will be logged. If one file has an entry with a value that is different from the other, that too will be logged.
--------------------------------------------------------------------------------
/uart/readLine.c:
--------------------------------------------------------------------------------
1 | #include "driver/uart.h"
2 |
3 | char *readLine(uart_port_t uart) {
4 | static char line[256];
5 | int size;
6 | char *ptr = line;
7 | while(1) {
8 | size = uart_read_bytes(UART_NUM_1, (unsigned char *)ptr, 1, portMAX_DELAY);
9 | if (size == 1) {
10 | if (*ptr == '\n') {
11 | *ptr = 0;
12 | return line;
13 | }
14 | ptr++;
15 | } // End of read a character
16 | } // End of loop
17 | } // End of readLine
18 |
--------------------------------------------------------------------------------
/vfs/spiffs/spiffs_vfs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * spiffs_vfs.h
3 | *
4 | * Created on: Dec 3, 2016
5 | * Author: kolban
6 | */
7 |
8 | #ifndef MAIN_SPIFFS_VFS_H_
9 | #define MAIN_SPIFFS_VFS_H_
10 | #include "spiffs.h"
11 | void spiffs_registerVFS(char *mountPoint, spiffs *fs);
12 |
13 |
14 | #endif /* MAIN_SPIFFS_VFS_H_ */
15 |
--------------------------------------------------------------------------------
/vfs/vfs-skeleton/.gitignore:
--------------------------------------------------------------------------------
1 | build/
2 | sdkconfig.old
3 |
--------------------------------------------------------------------------------
/vfs/vfs-skeleton/README.md:
--------------------------------------------------------------------------------
1 | #VFS
2 |
3 |
--------------------------------------------------------------------------------
/vfs/vfs-skeleton/main/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Test the Virtual File System
3 | *
4 | * Perform a test against the Virtual File System.
5 | *
6 | * For additional details and documentation see:
7 | * * Free book on ESP32 - https://leanpub.com/kolban-ESP32
8 | *
9 | *
10 | * Neil Kolban
11 | *
12 | */
13 | #include "freertos/FreeRTOS.h"
14 | #include "esp_wifi.h"
15 | #include "esp_system.h"
16 | #include "esp_event.h"
17 | #include "esp_event_loop.h"
18 | #include "esp_log.h"
19 | #include "nvs_flash.h"
20 | #include "driver/gpio.h"
21 | #include "vfsTest.h"
22 | #include "stdio.h"
23 | #include "fcntl.h"
24 |
25 | char tag[] = "vfs-skeleton";
26 | esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
27 | {
28 | return ESP_OK;
29 | }
30 |
31 | int app_main(void)
32 | {
33 | nvs_flash_init();
34 | system_init();
35 | tcpip_adapter_init();
36 | ESP_ERROR_CHECK( esp_event_loop_init(wifi_event_handler, NULL) );
37 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
38 | ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
39 | ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
40 | ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
41 | wifi_config_t sta_config = {
42 | .sta = {
43 | .ssid = "access_point_name",
44 | .password = "password",
45 | .bssid_set = false
46 | }
47 | };
48 | ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
49 | //ESP_ERROR_CHECK( esp_wifi_start() );
50 | //ESP_ERROR_CHECK( esp_wifi_connect() );
51 |
52 | // Perform the tests on the VFS
53 | registerTestVFS("/data");
54 | ESP_LOGI(tag, "vfs registered");
55 |
56 | FILE *file = fopen("/data/x", "w");
57 | if (file == NULL) {
58 | ESP_LOGE(tag, "failed to open file");
59 | return 0;
60 | }
61 |
62 | fprintf(file, "Hello!");
63 | return 0;
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/vfs/vfs-skeleton/main/vfsTest.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Test the Virtual File System
3 | *
4 | * Perform a test against the Virtual File System.
5 | *
6 | * For additional details and documentation see:
7 | * * Free book on ESP32 - https://leanpub.com/kolban-ESP32
8 | *
9 | *
10 | * Neil Kolban
11 | *
12 | */
13 |
14 | #ifndef MAIN_VFSTEST_H_
15 | #define MAIN_VFSTEST_H_
16 |
17 | void registerTestVFS(char *mountPoint);
18 |
19 | #endif /* MAIN_VFSTEST_H_ */
20 |
--------------------------------------------------------------------------------
/wifi/fragments/auth_mode_to_string.c:
--------------------------------------------------------------------------------
1 | char *authModeToString(wifi_auth_mode_t mode) {
2 | switch(mode) {
3 | case WIFI_AUTH_OPEN:
4 | return "open";
5 | case WIFI_AUTH_WEP:
6 | return "wep";
7 | case WIFI_AUTH_WPA_PSK:
8 | return "wpa";
9 | case WIFI_AUTH_WPA2_PSK:
10 | return "wpa2";
11 | case WIFI_AUTH_WPA_WPA2_PSK:
12 | return "wpa_wpa2";
13 | default:
14 | return "unknown";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------