Start publishing with C
Create a C client that publishes data through topics on Diffusion™ Cloud.
For more information about dependencies on each supported platform, see C.
- By including diffusion.h before any APR includes. The diffusion.h file sets these values.
- As command-line flags
To complete this example, you need a Diffusion Cloud service and a development system with the .NET Framework installed on it. For more information about getting a Diffusion Cloud service, see Getting started with Diffusion Cloud.
You also require a named user that has a role with the "ADMINISTRATOR" role. For more information about roles and permissions, see Role-based authorization.
and permissions. For example, theThis example also requires the external cJSON library which can be downloaded from https://github.com/DaveGamble/cJSON/.
The client updates the value of the processes topic. You can see the value of the processes topic by using the Diffusion Cloud Dashboard's test client or by creating a subscribing client to subscribe to the topic. For more information, see Start subscribing with C.
# The following two variables must be set. # # Directory containing the C client include files. # DIFFUSION_C_CLIENT_INCDIR = # # Directory containing libdiffusion.a # DIFFUSION_C_CLIENT_LIBDIR = ifndef DIFFUSION_C_CLIENT_INCDIR $(error DIFFUSION_C_CLIENT_INCDIR is not set) endif ifndef DIFFUSION_C_CLIENT_LIBDIR $(error DIFFUSION_C_CLIENT_LIBDIR is not set) endif CC = gcc # Extra definitions from parent directory, if they exist. -include ../makefile.defs CFLAGS += -g -Wall -Werror -std=c99 -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=700 -I$(DIFFUSION_C_CLIENT_INCDIR) LDFLAGS += $(DIFFUSION_C_CLIENT_LIBDIR)/libdiffusion.a -lpthread -lpcre -lz $(LIBS) # If you have openssl installed then you can uncomment these. ifdef HAVE_OPEN_SSL LDFLAGS += -lssl -lcrypto endif ARFLAGS += SOURCES = json/cjson-publishing-example.c TARGETDIR = target OBJDIR = $(TARGETDIR)/objs BINDIR = $(TARGETDIR)/bin OBJECTS = $(SOURCES:.c=.o) TARGETS = cjson-publishing-example all: prepare $(TARGETS) .PHONY: all prepare: mkdir -p $(OBJDIR) $(BINDIR) $(OBJDIR)/%.o: %.c $(CC) $(CFLAGS) -c -o $@ $< cjson-publishing-example: json/cjson-publishing-example.c json/cJSON.c $(CC) $^ $(CFLAGS) $(LDFLAGS) -lm -o $(BINDIR)/$@ clean: rm -rf $(TARGETS) $(OBJECTS) $(TARGETDIR) core a.out
This page last modified: 2019/11/22